From a13f10564ba1c68825f53a551ce8f7d989947bf2 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 3 Sep 2025 19:37:27 -0400 Subject: [PATCH] feat: basic online working with relay --- Assets/Core/Objects/CameraGroup.prefab | 4 +- Assets/Core/Objects/NetworkManager.prefab | 10 +- Assets/Player/Objects/Player.prefab | 57 ++++---- Assets/Scenes/NetworkTest.unity | 132 ++++++++++++++---- Assets/Scripts/Core/GameManager.cs | 24 +++- Assets/Scripts/Core/LockOnManager.cs | 23 ++- .../Scripts/Core/Networking/SessionManager.cs | 1 + Assets/Scripts/Player/CustomInputHandler.cs | 79 +++++++++++ .../Scripts/Player/CustomInputHandler.cs.meta | 2 + Assets/Scripts/Player/Player.cs | 37 ++++- Assets/Scripts/Player/PlayerControls.cs | 5 + 11 files changed, 299 insertions(+), 75 deletions(-) create mode 100644 Assets/Scripts/Player/CustomInputHandler.cs create mode 100644 Assets/Scripts/Player/CustomInputHandler.cs.meta diff --git a/Assets/Core/Objects/CameraGroup.prefab b/Assets/Core/Objects/CameraGroup.prefab index a43b85e..7927170 100644 --- a/Assets/Core/Objects/CameraGroup.prefab +++ b/Assets/Core/Objects/CameraGroup.prefab @@ -235,7 +235,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3727451710788063110} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 89875cdc57c54474a8a74efd9b2a3b5d, type: 3} m_Name: @@ -456,7 +456,6 @@ MonoBehaviour: m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0} m_RequiresDepthTexture: 0 m_RequiresColorTexture: 0 - m_Version: 2 m_TaaSettings: m_Quality: 3 m_FrameInfluence: 0.1 @@ -464,6 +463,7 @@ MonoBehaviour: m_MipBias: 0 m_VarianceClampScale: 0.9 m_ContrastAdaptiveSharpening: 0 + m_Version: 2 --- !u!114 &8677805350076133661 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Core/Objects/NetworkManager.prefab b/Assets/Core/Objects/NetworkManager.prefab index 54711eb..277f7fc 100644 --- a/Assets/Core/Objects/NetworkManager.prefab +++ b/Assets/Core/Objects/NetworkManager.prefab @@ -18,7 +18,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!4 &673391980113178687 Transform: m_ObjectHideFlags: 0 @@ -27,7 +27,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3608368543505542050} serializedVersion: 2 - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 9.256327, y: -15.74262, z: 7.6148796} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -50,7 +50,7 @@ MonoBehaviour: NetworkConfig: ProtocolVersion: 0 NetworkTransport: {fileID: 8202239970190248966} - PlayerPrefab: {fileID: 0} + PlayerPrefab: {fileID: 2757828562731694833, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3} Prefabs: NetworkPrefabsLists: - {fileID: 11400000, guid: 935babab2affb8f4683610c7e463c3ad, type: 2} @@ -69,7 +69,7 @@ MonoBehaviour: LoadSceneTimeOut: 120 SpawnTimeout: 10 EnableNetworkLogs: 1 - NetworkTopology: 0 + NetworkTopology: 1 UseCMBService: 0 AutoSpawnPlayerPrefabClientSide: 1 NetworkMessageMetrics: 1 @@ -113,7 +113,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3608368543505542050} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 31709e0224b48e24b8e5311541392a97, type: 3} m_Name: diff --git a/Assets/Player/Objects/Player.prefab b/Assets/Player/Objects/Player.prefab index 01917ab..357dc9d 100644 --- a/Assets/Player/Objects/Player.prefab +++ b/Assets/Player/Objects/Player.prefab @@ -120,6 +120,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 7329826263822975762} + - component: {fileID: 2538182172493791937} - component: {fileID: 7494367001870099223} - component: {fileID: 8163344541298437235} - component: {fileID: 679199079481597207} @@ -129,7 +130,6 @@ GameObject: - component: {fileID: 2129000951396423518} - component: {fileID: 2842793574603981349} - component: {fileID: 43868462096200776} - - component: {fileID: 2538182172493791937} - component: {fileID: 6067609290387865387} m_Layer: 0 m_Name: Player @@ -154,6 +154,31 @@ Transform: - {fileID: 2655796284435897345} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2538182172493791937 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2757828562731694833} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} + m_Name: + m_EditorClassIdentifier: Unity.Netcode.Runtime::Unity.Netcode.NetworkObject + GlobalObjectIdHash: 3816484910 + InScenePlacedSourceGlobalObjectIdHash: 0 + DeferredDespawnTick: 0 + Ownership: 1 + AlwaysReplicateAsRoot: 0 + SynchronizeTransform: 1 + ActiveSceneSynchronization: 0 + SceneMigrationSynchronization: 1 + SpawnWithObservers: 1 + DontDestroyWithOwner: 0 + AutoObjectParentSync: 1 + SyncOwnerTransformWhenParented: 1 + AllowOwnerToParent: 0 --- !u!114 &7494367001870099223 MonoBehaviour: m_ObjectHideFlags: 0 @@ -166,6 +191,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 0c0da0317d344ea49b810f0010efefa8, type: 3} m_Name: m_EditorClassIdentifier: + ShowTopMostFoldoutHeaderGroup: 1 controls: {fileID: 0} camera: {fileID: 0} --- !u!114 &8163344541298437235 @@ -433,7 +459,7 @@ MonoBehaviour: m_ActionEvents: [] m_NeverAutoSwitchControlSchemes: 1 m_DefaultControlScheme: Controller - m_DefaultActionMap: b2eefcc8-f0a6-4007-854d-f0b59159e624 + m_DefaultActionMap: In-Game m_SplitScreenIndex: -1 m_Camera: {fileID: 0} --- !u!143 &2106585328495276993 @@ -556,31 +582,6 @@ MonoBehaviour: Radius: 0.5 targetGroup: {fileID: 0} lockOnDocument: {fileID: 0} ---- !u!114 &2538182172493791937 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2757828562731694833} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} - m_Name: - m_EditorClassIdentifier: Unity.Netcode.Runtime::Unity.Netcode.NetworkObject - GlobalObjectIdHash: 3816484910 - InScenePlacedSourceGlobalObjectIdHash: 0 - DeferredDespawnTick: 0 - Ownership: 1 - AlwaysReplicateAsRoot: 0 - SynchronizeTransform: 1 - ActiveSceneSynchronization: 0 - SceneMigrationSynchronization: 1 - SpawnWithObservers: 1 - DontDestroyWithOwner: 0 - AutoObjectParentSync: 1 - SyncOwnerTransformWhenParented: 1 - AllowOwnerToParent: 0 --- !u!114 &6067609290387865387 MonoBehaviour: m_ObjectHideFlags: 0 @@ -596,7 +597,7 @@ MonoBehaviour: ShowTopMostFoldoutHeaderGroup: 1 NetworkTransformExpanded: 0 AutoOwnerAuthorityTickOffset: 1 - PositionInterpolationType: 0 + PositionInterpolationType: 2 RotationInterpolationType: 0 ScaleInterpolationType: 0 PositionLerpSmoothing: 1 diff --git a/Assets/Scenes/NetworkTest.unity b/Assets/Scenes/NetworkTest.unity index 9997a43..ead30df 100644 --- a/Assets/Scenes/NetworkTest.unity +++ b/Assets/Scenes/NetworkTest.unity @@ -255,6 +255,41 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 12023376} m_CullTransparentMesh: 1 +--- !u!1 &16776950 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 16776951} + m_Layer: 5 + m_Name: Online Controls + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &16776951 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 16776950} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1433518867} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} --- !u!43 &55045520 Mesh: m_ObjectHideFlags: 0 @@ -934,6 +969,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 4906743167862811726, guid: 86fe521c4bae13c4ab1ad5a357fe8d47, type: 3} insertIndex: -1 addedObject: {fileID: 1293873423} + - targetCorrespondingSourceObject: {fileID: 4906743167862811726, guid: 86fe521c4bae13c4ab1ad5a357fe8d47, type: 3} + insertIndex: -1 + addedObject: {fileID: 16776951} m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 86fe521c4bae13c4ab1ad5a357fe8d47, type: 3} --- !u!1 &100788157 @@ -1681,6 +1719,67 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 336882625} m_CullTransparentMesh: 1 +--- !u!1 &394357389 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 3727451710788063110, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} + m_PrefabInstance: {fileID: 870221777} + m_PrefabAsset: {fileID: 0} +--- !u!114 &394357396 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 4828207810450504966, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} + m_PrefabInstance: {fileID: 870221777} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 394357389} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3b5d7c088409d9a40b7b09aa707777f8, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &394357398 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 394357389} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 058c862723373ca43913637463aff84a, type: 3} + m_Name: + m_EditorClassIdentifier: Core::CustomInputHandler + ScanRecursively: 1 + SuppressInputWhileBlending: 1 + IgnoreTimeScale: 0 + m_ControllerManager: + Controllers: + - Name: Look Orbit X + Owner: {fileID: 394357396} + Enabled: 1 + Input: + Input: {fileID: 6185001796860367008, guid: 94c7611bb3f64b248940847af54844cf, type: 3} + InputValue: 0 + Driver: + AccelTime: 0 + DecelTime: 0 + - Name: Look Orbit Y + Owner: {fileID: 394357396} + Enabled: 1 + Input: + Input: {fileID: 6185001796860367008, guid: 94c7611bb3f64b248940847af54844cf, type: 3} + InputValue: 0 + Driver: + AccelTime: 0 + DecelTime: 0 + - Name: Orbit Scale + Owner: {fileID: 394357396} + Enabled: 1 + Input: + Input: {fileID: 6185001796860367008, guid: 94c7611bb3f64b248940847af54844cf, type: 3} + InputValue: 0 + Driver: + AccelTime: 0 + DecelTime: 0 + PlayerInput: {fileID: 0} --- !u!1001 &400326425 PrefabInstance: m_ObjectHideFlags: 0 @@ -2442,7 +2541,10 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 3727451710788063110, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} + insertIndex: 6 + addedObject: {fileID: 394357398} m_SourcePrefab: {fileID: 100100000, guid: 6ae1b39ffbe1f0f468d521bb08a8b547, type: 3} --- !u!1 &927616996 GameObject: @@ -6461,18 +6563,6 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 0} m_Modifications: - - target: {fileID: 541335868644022067, guid: 222e4e6c5bda2b64da9c38abf6dc55bb, type: 3} - propertyPath: m_Enabled - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 541335868644022067, guid: 222e4e6c5bda2b64da9c38abf6dc55bb, type: 3} - propertyPath: NetworkConfig.PlayerPrefab - value: - objectReference: {fileID: 2757828562731694833, guid: 091cfac8be4c5a144a0b8997a9f1ff28, type: 3} - - target: {fileID: 541335868644022067, guid: 222e4e6c5bda2b64da9c38abf6dc55bb, type: 3} - propertyPath: NetworkConfig.NetworkTopology - value: 1 - objectReference: {fileID: 0} - target: {fileID: 673391980113178687, guid: 222e4e6c5bda2b64da9c38abf6dc55bb, type: 3} propertyPath: m_LocalPosition.x value: 9.256327 @@ -6517,22 +6607,6 @@ PrefabInstance: propertyPath: m_Name value: NetworkManager objectReference: {fileID: 0} - - target: {fileID: 3608368543505542050, guid: 222e4e6c5bda2b64da9c38abf6dc55bb, type: 3} - propertyPath: m_IsActive - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 3971766729977841875, guid: 222e4e6c5bda2b64da9c38abf6dc55bb, type: 3} - propertyPath: m_Enabled - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8202239970190248966, guid: 222e4e6c5bda2b64da9c38abf6dc55bb, type: 3} - propertyPath: m_Enabled - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 8202239970190248966, guid: 222e4e6c5bda2b64da9c38abf6dc55bb, type: 3} - propertyPath: m_ProtocolType - value: 1 - objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] diff --git a/Assets/Scripts/Core/GameManager.cs b/Assets/Scripts/Core/GameManager.cs index 0da629e..20bff43 100644 --- a/Assets/Scripts/Core/GameManager.cs +++ b/Assets/Scripts/Core/GameManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using Reset.Core.Tools; +using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Users; @@ -12,7 +13,17 @@ namespace Reset{ public static GameObject Input; public static SessionManager Session; - public static GameObject Player; + private static GameObject player; + + public static GameObject Player{ + get{ return player; } + set{ player = value; } + } + + [RuntimeInitializeOnLoadMethod] + static void Reset(){ + player = null; + } [RuntimeInitializeOnLoadMethod] static void PopulateSceneReferences(){ @@ -35,6 +46,17 @@ namespace Reset{ playerUser = InputUser.PerformPairingWithDevice(device, playerUser, InputUserPairingOptions.UnpairCurrentDevicesFromUser); } + public static GameObject FindNewPlayer(){ + var allPlayers = GameObject.FindGameObjectsWithTag("Player"); + for (int i = 0; i < allPlayers.Length; i++) { + if (allPlayers[i].GetComponent() && allPlayers[i].GetComponent().IsLocalPlayer) { + return allPlayers[i]; + } + } + + return null; + } + public static void RequestNewController(){ try { GameObject.Find("Input Selector").GetComponent().AwaitNewInput(); diff --git a/Assets/Scripts/Core/LockOnManager.cs b/Assets/Scripts/Core/LockOnManager.cs index c103ca9..bf98e5a 100644 --- a/Assets/Scripts/Core/LockOnManager.cs +++ b/Assets/Scripts/Core/LockOnManager.cs @@ -6,6 +6,7 @@ using Reset; using Sirenix.OdinInspector; using Unity.Cinemachine; using UnityEngine; +using UnityEngine.InputSystem; using UnityEngine.Serialization; using UnityEngine.UIElements; using Vector2 = UnityEngine.Vector2; @@ -44,8 +45,7 @@ public class LockOnManager : MonoBehaviour{ private Label elementLabelName; private VisualElement elementRoot; - // Start is called once before the first execution of Update after the MonoBehaviour is created - void Start(){ + private void Awake(){ // Register as singleton if (Instance == null) { Instance = this; @@ -57,11 +57,10 @@ public class LockOnManager : MonoBehaviour{ // References from camera targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent(); lockOnDocument = GameManager.UI.transform.Find("Lock On").GetComponent(); - - // Set the camera's target as the player - targetGroup.Targets.Add(new CinemachineTargetGroup.Target{Object = transform, Radius = 3.5f, Weight = 1f}); - GameManager.Camera.transform.Find("Cinemachine").GetComponent().Target.TrackingTarget = transform; + } + // Start is called once before the first execution of Update after the MonoBehaviour is created + void Start(){ // Quick check for things in lock-on target that aren't lock-onable if (mainTarget != null && mainTarget.gameObject.GetComponent() == null) { mainTarget.gameObject.AddComponent(); @@ -81,6 +80,18 @@ public class LockOnManager : MonoBehaviour{ } } + public void AttachCamera(GameObject target){ + targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent(); + Debug.Log($"{GameManager.Camera}"); + + // Set the camera's target as the player + targetGroup.Targets.Add(new CinemachineTargetGroup.Target{Object = target.transform, Radius = 3.5f, Weight = 1f}); + GameManager.Camera.transform.Find("Cinemachine").GetComponent().Target.TrackingTarget = target.transform; + GameManager.Camera.transform.Find("Cinemachine").GetComponent().PlayerInput = + GetComponent(); + GameManager.Camera.transform.Find("Cinemachine").GetComponent().AddEvents(); + } + void Update(){ if (mainTarget != null && mainTarget.gameObject.GetComponent() == null) { mainTarget.gameObject.AddComponent(); diff --git a/Assets/Scripts/Core/Networking/SessionManager.cs b/Assets/Scripts/Core/Networking/SessionManager.cs index 420f992..d33f0f5 100644 --- a/Assets/Scripts/Core/Networking/SessionManager.cs +++ b/Assets/Scripts/Core/Networking/SessionManager.cs @@ -13,6 +13,7 @@ using Unity.Services.Core; public class SessionManager : MonoBehaviour{ // Start is called once before the first execution of Update after the MonoBehaviour is created void Start(){ + } // Update is called once per frame diff --git a/Assets/Scripts/Player/CustomInputHandler.cs b/Assets/Scripts/Player/CustomInputHandler.cs new file mode 100644 index 0000000..2508684 --- /dev/null +++ b/Assets/Scripts/Player/CustomInputHandler.cs @@ -0,0 +1,79 @@ +using System; +using UnityEngine; +using UnityEngine.InputSystem; +using Unity.Cinemachine; + +// This class receives input from a PlayerInput component and disptaches it +// to the appropriate Cinemachine InputAxis. The playerInput component should +// be on the same GameObject, or specified in the PlayerInput field. +class CustomInputHandler : InputAxisControllerBase +{ + [Header("Input Source Override")] + public PlayerInput PlayerInput; + + void Awake() + { + // // When the PlayerInput receives an input, send it to all the controllers + // if (PlayerInput == null) + // TryGetComponent(out PlayerInput); + // if (PlayerInput == null) + // Debug.LogError("Cannot find PlayerInput component"); + // else + // { + // PlayerInput.notificationBehavior = PlayerNotifications.InvokeCSharpEvents; + // PlayerInput.onActionTriggered += (value) => + // { + // for (var i = 0; i < Controllers.Count; i++) + // Controllers[i].Input.ProcessInput(value.action); + // }; + // } + } + + // We process user input on the Update clock + void Update() + { + if (Application.isPlaying) + UpdateControllers(); + Controllers[0].Input.ProcessInput(PlayerInput); + Controllers[1].Input.ProcessInput(PlayerInput); + } + + public void AddEvents(){ + // // PlayerInput.notificationBehavior = PlayerNotifications.InvokeCSharpEvents; + // += (value) => + // { + // for (var i = 0; i < Controllers.Count; i++) + // Controllers[i].Input.ProcessInput(value.action); + // }; + } + + // Controllers will be instances of this class. + [Serializable] + public class Reader : IInputAxisReader + { + public InputActionReference Input; + Vector2 m_Value; // the cached value of the input + + public void ProcessInput(PlayerInput input){ + + // // If it's my action then cache the new value + // if (Input != null && Input.action.id == action.id) + // { + // if (action.expectedControlType == "Vector2") + // m_Value = action.ReadValue(); + // else + // m_Value.x = m_Value.y = action.ReadValue(); + // } + + m_Value = input.actions["Look"].ReadValue(); + m_Value.x *= 200f; + m_Value.y *= -100f; + } + + // IInputAxisReader interface: Called by the framework to read the input value + public float GetValue(UnityEngine.Object context, IInputAxisOwner.AxisDescriptor.Hints hint) + { + return (hint == IInputAxisOwner.AxisDescriptor.Hints.Y ? m_Value.y : m_Value.x); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/Player/CustomInputHandler.cs.meta b/Assets/Scripts/Player/CustomInputHandler.cs.meta new file mode 100644 index 0000000..20ad292 --- /dev/null +++ b/Assets/Scripts/Player/CustomInputHandler.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 058c862723373ca43913637463aff84a \ No newline at end of file diff --git a/Assets/Scripts/Player/Player.cs b/Assets/Scripts/Player/Player.cs index a3dfd1d..47c2dcd 100644 --- a/Assets/Scripts/Player/Player.cs +++ b/Assets/Scripts/Player/Player.cs @@ -1,26 +1,55 @@ using System; +using System.Collections; using Reset; using Reset.Core.Tools; using UnityEngine; using Sirenix.OdinInspector; +using Unity.Netcode; -public class Player : MonoBehaviour{ +public class Player : NetworkBehaviour{ [HideInInspector] public PlayerControls controls; [HideInInspector] public new PlayerCamera camera; void Awake(){ GameManager.Player = gameObject; controls = GetComponent(); - GameManager.RequestNewController(); } void Start() { - - Debug.Log(GameManager.Player); + if (!NetworkManager.Singleton.IsConnectedClient && !NetworkManager.Singleton.IsHost) { + Attach(); + } else { + StartCoroutine(WaitForOnline()); + } } + private IEnumerator WaitForOnline(){ + while (!NetworkManager.Singleton.didAwake) { + Debug.Log("waiting"); + yield return null; + } + + // Debug.Log($"{IsHost}, {IsClient}, {IsLocalPlayer}"); + if (IsLocalPlayer){ + GameManager.Player = gameObject; + Attach(); + } + } + + public void Attach(){ + if (GameManager.Player == gameObject){ + GameManager.RequestNewController(); + GetComponent().AttachCamera(gameObject); + } + } + + protected override void OnNetworkPostSpawn(){ + // GetComponent().AttachCamera(gameObject); + } + + // Update is called once per frame void Update() { diff --git a/Assets/Scripts/Player/PlayerControls.cs b/Assets/Scripts/Player/PlayerControls.cs index 287b8c0..91f5c70 100644 --- a/Assets/Scripts/Player/PlayerControls.cs +++ b/Assets/Scripts/Player/PlayerControls.cs @@ -7,7 +7,9 @@ using UnityEngine.UIElements; using NodeCanvas; using NodeCanvas.Framework; using ParadoxNotion; +using Reset; using Sirenix.OdinInspector; +using Unity.Cinemachine; public class PlayerControls : MonoBehaviour{ // References @@ -63,6 +65,9 @@ public class PlayerControls : MonoBehaviour{ public void OnLook(InputValue value){ rawLookInput.x = value.Get().x; rawLookInput.y = value.Get().y; + + // GameManager.Camera.transform.Find("Cinemachine").GetComponent().Controllers[0].InputValue = rawLookInput.x * 200; + // GameManager.Camera.transform.Find("Cinemachine").GetComponent().Controllers[1].InputValue = rawLookInput.y * 100; } public void OnSprint(){