Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Opencraft Education #1

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
54 changes: 54 additions & 0 deletions Prefabs/Player/MultiplayPlayer.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ MonoBehaviour:
inputJump: 0
inputPrimaryAction: 0
inputSecondaryAction: 0
selectedItemIndex: 0
inputThirdAction: 0
playerEntityExists: 0
playerEntityRequestSent: 0
selectableItems: 010000000300000010000000120000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d0000000e000000
--- !u!114 &-3399718007712543476
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -205,6 +208,57 @@ MonoBehaviour:
m_CallState: 2
m_ActionId: 52bd4c51-0503-4ffb-b405-5a778b3906fc
m_ActionName: Player Controls/Exit[/Keyboard/escape]
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 207901908825964653}
m_TargetAssemblyTypeName: PolkaDOTS.Multiplay.MultiplayPlayerController,
PolkaDOTS
m_MethodName: OnLeftItem
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_ActionId: beed57c0-e24f-42ba-9a6d-ef10bae29e7d
m_ActionName: Player Controls/LeftItem[/Keyboard/1]
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 207901908825964653}
m_TargetAssemblyTypeName: PolkaDOTS.Multiplay.MultiplayPlayerController,
PolkaDOTS
m_MethodName: OnRightItem
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_ActionId: 880b5a06-139d-40fc-bd59-67cab59e47a5
m_ActionName: Player Controls/RightItem[/Keyboard/2]
- m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 207901908825964653}
m_TargetAssemblyTypeName: PolkaDOTS.Multiplay.MultiplayPlayerController,
PolkaDOTS
m_MethodName: OnThirdAction
m_Mode: 0
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_ActionId: 4a4ddd8c-f219-4ac5-992e-b7073be2ab9a
m_ActionName: Player Controls/ThirdAction[/Keyboard/3]
m_DefaultActionMap: Player Controls
--- !u!20 &3141172503242693401
Camera:
Expand Down
60 changes: 60 additions & 0 deletions Prefabs/Player/PlayerInput.inputactions
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,33 @@
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "LeftItem",
"type": "Button",
"id": "beed57c0-e24f-42ba-9a6d-ef10bae29e7d",
"expectedControlType": "Button",
"processors": "",
"interactions": "Press",
"initialStateCheck": false
},
{
"name": "RightItem",
"type": "Button",
"id": "880b5a06-139d-40fc-bd59-67cab59e47a5",
"expectedControlType": "Button",
"processors": "",
"interactions": "Press",
"initialStateCheck": false
},
{
"name": "ThirdAction",
"type": "Button",
"id": "4a4ddd8c-f219-4ac5-992e-b7073be2ab9a",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
Expand Down Expand Up @@ -322,6 +349,39 @@
"action": "Exit",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "78e3a7a9-1ae1-4043-9f43-aa2ea4f7c665",
"path": "<Keyboard>/1",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "LeftItem",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "a47d4061-38fd-4f33-9e3e-b022e09d51ad",
"path": "<Keyboard>/2",
"interactions": "",
"processors": "",
"groups": "Keyboard And Mouse",
"action": "RightItem",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "0725be4a-1d7f-42b8-ae5e-9073377df450",
"path": "<Keyboard>/3",
"interactions": "",
"processors": "",
"groups": "",
"action": "ThirdAction",
"isComposite": false,
"isPartOfComposite": false
}
]
},
Expand Down
19 changes: 10 additions & 9 deletions Runtime/Configuration/ApplicationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public static class ApplicationConfig
public static readonly CommandLineParser.FlagArgument GetRemoteConfig = new CommandLineParser.FlagArgument("-remoteConfig", false);
public static readonly CommandLineParser.StringArgument DeploymentURL = new CommandLineParser.StringArgument("-deploymentURL", "127.0.0.1");
public static readonly CommandLineParser.IntArgument DeploymentPort = new CommandLineParser.IntArgument("-deploymentPort", 7980);

// ================== NETWORKING ==================
public static readonly CommandLineParser.IntArgument NetworkTickRate = new CommandLineParser.IntArgument("-networkTickRate", 60);
public static readonly CommandLineParser.IntArgument SimulationTickRate = new CommandLineParser.IntArgument("-simulationTickRate", 60);
public static readonly CommandLineParser.IntArgument MaxSimulationStepsPerFrame = new CommandLineParser.IntArgument("-maxSimulationStepsPerFrame", 4);
public static readonly CommandLineParser.IntArgument MaxSimulationStepBatchSize = new CommandLineParser.IntArgument("-maxSimulationStepBatchSize", 4);
public static readonly CommandLineParser.IntArgument MaxPredictAheadTimeMS = new CommandLineParser.IntArgument("-maxPredictAheadTimeMS", 250);
public static readonly CommandLineParser.FlagArgument DisablePrediction = new CommandLineParser.FlagArgument("-disablePrediction", false);

// ================== APPLICATION ==================
public static readonly CommandLineParser.FlagArgument NoGraphics = new CommandLineParser.FlagArgument("-nographics", false);
public static readonly CommandLineParser.FlagArgument DebugEnabled = new CommandLineParser.FlagArgument("-debug", false);
Expand All @@ -39,8 +39,8 @@ public static class ApplicationConfig
public static readonly CommandLineParser.IntArgument Duration = new CommandLineParser.IntArgument("-duration", -1);
public static readonly CommandLineParser.IntArgument Delay = new CommandLineParser.IntArgument("-startDelay", 0);
public static readonly CommandLineParser.IntArgument UserID = new CommandLineParser.IntArgument("-userID", 0);


// ================== MULTIPLAY ==================
public static readonly CommandLineParser.EnumArgument<MultiplayStreamingRoles> MultiplayStreamingRole = new CommandLineParser.EnumArgument<MultiplayStreamingRoles>("-multiplayRole", MultiplayStreamingRoles.Disabled);
public static readonly CommandLineParser.StringArgument SignalingUrl = new CommandLineParser.StringArgument("-signalingUrl", "ws://127.0.0.1:7981");
Expand All @@ -49,18 +49,19 @@ public static class ApplicationConfig
//internal static readonly CommandLineParser.StringArrayArgument IceServerUrls = new CommandLineParser.StringArrayArgument("-iceServerUrl");
//internal static readonly CommandLineParser.StringArgument IceServerUsername = new CommandLineParser.StringArgument("-iceServerUsername");
//internal static readonly CommandLineParser.StringArgument IceServerCredential = new CommandLineParser.StringArgument("-iceServerCredential");

// ================== EMULATION ==================
public static readonly CommandLineParser.EnumArgument<EmulationType> EmulationType = new CommandLineParser.EnumArgument<EmulationType>("-emulationType", Deployment.EmulationType.None);
public static readonly CommandLineParser.FilePathArgument EmulationFile = new CommandLineParser.FilePathArgument("-emulationFile", Application.persistentDataPath + '\\' + "recordedInputs.inputtrace");
public static readonly CommandLineParser.IntArgument NumSimulatedPlayers = new CommandLineParser.IntArgument("-numSimulatedPlayers", 1);
public static readonly CommandLineParser.IntArgument SimulatedJoinInterval = new CommandLineParser.IntArgument("-simulatedJoinInterval", 0);

// ================== STATISTICS ==================
public static readonly CommandLineParser.FlagArgument LogStats = new CommandLineParser.FlagArgument("-logStats", false);
public static readonly CommandLineParser.FilePathArgument StatsFilePath = new CommandLineParser.FilePathArgument("-statsFile", Application.persistentDataPath + '\\' + "stats.csv");


}

public static readonly CommandLineParser.FlagArgument ActiveLogic = new CommandLineParser.FlagArgument("-activeLogic", true);
public static readonly CommandLineParser.IntArgument CircuitX = new CommandLineParser.IntArgument("-circuitX", 1);
public static readonly CommandLineParser.IntArgument CircuitZ = new CommandLineParser.IntArgument("-circuitZ", 1);
}
}
77 changes: 55 additions & 22 deletions Runtime/Player/Multiplay/MultiplayPlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using Unity.RenderStreaming;
using Unity.Serialization;
using UnityEditor;
using Unity.Mathematics;
using System.Collections.Generic;

/*
* Gathers input from Player GameObject
Expand All @@ -14,24 +16,29 @@ namespace PolkaDOTS.Multiplay
// Collects input either from local devices or a remote input stream using InputActions
public class MultiplayPlayerController : MonoBehaviour
{

[SerializeField] InputReceiver playerInput;
[DontSerialize] public string username;
[DontSerialize]public Vector2 inputMovement;
[DontSerialize]public Vector2 inputLook;
[DontSerialize]public bool inputJump;
[DontSerialize]public bool inputPrimaryAction = false;
[DontSerialize]public bool inputSecondaryAction = false;
[DontSerialize]public bool playerEntityExists;
[DontSerialize]public bool playerEntityRequestSent;
[DontSerialize]public Entity playerEntity;
[DontSerialize] public Vector2 inputMovement;
[DontSerialize] public Vector2 inputLook;
[DontSerialize] public bool inputJump;
[DontSerialize] public bool inputPrimaryAction = false;
[DontSerialize] public bool inputSecondaryAction = false;
[DontSerialize] public int selectedItemIndex;
[DontSerialize] public bool inputThirdAction = false;
[DontSerialize] public bool playerEntityExists;
[DontSerialize] public bool playerEntityRequestSent;
[DontSerialize] public Entity playerEntity;
[DontSerialize] public List<int> selectableItems = new List<int> { 1, 15, 17, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };

protected void Awake()
{
playerInput.onDeviceChange += OnDeviceChange;
username = $"{ApplicationConfig.UserID.Value}";
selectedItemIndex = 0;
}


private void OnEnable()
{
}
Expand All @@ -45,17 +52,17 @@ void OnDeviceChange(InputDevice device, InputDeviceChange change)
switch (change)
{
case InputDeviceChange.Added:
{
playerInput.PerformPairingWithDevice(device);
CheckPairedDevices();
return;
}
{
playerInput.PerformPairingWithDevice(device);
CheckPairedDevices();
return;
}
case InputDeviceChange.Removed:
{
playerInput.UnpairDevices(device);
CheckPairedDevices();
return;
}
{
playerInput.UnpairDevices(device);
CheckPairedDevices();
return;
}
}
}

Expand Down Expand Up @@ -103,23 +110,23 @@ public void OnJump(InputAction.CallbackContext value)
inputJump = true;
}
}

public void OnPrimaryAction(InputAction.CallbackContext value)
{
if (value.performed)
{
inputPrimaryAction = true;
}
}

public void OnSecondaryAction(InputAction.CallbackContext value)
{
if (value.performed)
{
inputSecondaryAction = true;
}
}

public void OnEscapeAction(InputAction.CallbackContext value)
{
if (value.performed)
Expand All @@ -133,6 +140,32 @@ public void OnEscapeAction(InputAction.CallbackContext value)
#endif
}
}

public void OnLeftItem(InputAction.CallbackContext value)
{
if (value.performed)
{
selectedItemIndex = math.max(selectedItemIndex - 1, 0);
Debug.Log($"Selected item: {selectedItemIndex}");
}
}

public void OnRightItem(InputAction.CallbackContext value)
{
if (value.performed)
{
selectedItemIndex = math.min(selectedItemIndex + 1, selectableItems.Count - 1);
Debug.Log($"Selected item: {selectedItemIndex}");
}
}

public void OnThirdAction(InputAction.CallbackContext value)
{
if (value.performed)
{
inputThirdAction = true;
}
}
}
}

Loading