From 5fb3197aba9e681e6165cb1f4a1c6458f4ec6474 Mon Sep 17 00:00:00 2001 From: BOTAlex Date: Wed, 14 Feb 2024 16:29:24 +0100 Subject: [PATCH] I'm soo close to online multiplayer. I can almost taste it! --- .../Plugins/ParrelSync/ScriptableObjects.meta | 8 ++ .../ParrelSyncProjectSettings.asset | 15 +++ .../ParrelSyncProjectSettings.asset.meta | 8 ++ Assets/Prefabs/NetworkedGameSetup.prefab | 68 +++++++++++++ Assets/Prefabs/NetworkedGameSetup.prefab.meta | 7 ++ Assets/Scenes/GameScene.unity | 95 ++++++++++++++++--- Assets/Scripts/Blood/BloodComputeShader.cs | 2 + .../Managers/AudioManager/AudioManager.cs | 2 - .../Managers/Rumbling/RumbleManager.cs | 2 +- .../Scripts/Multiplayer/NetworkedGameSetup.cs | 26 ++++- .../Project.Scripts.Multiplayer.asmdef | 4 +- .../Scripts/Player/Movement/PlayerMovement.cs | 9 +- Assets/Scripts/Upgrade/Upgrader.cs | 14 +++ 13 files changed, 235 insertions(+), 25 deletions(-) create mode 100644 Assets/Plugins/ParrelSync/ScriptableObjects.meta create mode 100644 Assets/Plugins/ParrelSync/ScriptableObjects/ParrelSyncProjectSettings.asset create mode 100644 Assets/Plugins/ParrelSync/ScriptableObjects/ParrelSyncProjectSettings.asset.meta create mode 100644 Assets/Prefabs/NetworkedGameSetup.prefab create mode 100644 Assets/Prefabs/NetworkedGameSetup.prefab.meta diff --git a/Assets/Plugins/ParrelSync/ScriptableObjects.meta b/Assets/Plugins/ParrelSync/ScriptableObjects.meta new file mode 100644 index 0000000..06de1cb --- /dev/null +++ b/Assets/Plugins/ParrelSync/ScriptableObjects.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: be3350a372dbcf64d8639b5b0bd12cd5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/ParrelSync/ScriptableObjects/ParrelSyncProjectSettings.asset b/Assets/Plugins/ParrelSync/ScriptableObjects/ParrelSyncProjectSettings.asset new file mode 100644 index 0000000..0ec926c --- /dev/null +++ b/Assets/Plugins/ParrelSync/ScriptableObjects/ParrelSyncProjectSettings.asset @@ -0,0 +1,15 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c0011418c9d75434988a06b6df93b283, type: 3} + m_Name: ParrelSyncProjectSettings + m_EditorClassIdentifier: + m_OptionalSymbolicLinkFolders: [] diff --git a/Assets/Plugins/ParrelSync/ScriptableObjects/ParrelSyncProjectSettings.asset.meta b/Assets/Plugins/ParrelSync/ScriptableObjects/ParrelSyncProjectSettings.asset.meta new file mode 100644 index 0000000..5a12753 --- /dev/null +++ b/Assets/Plugins/ParrelSync/ScriptableObjects/ParrelSyncProjectSettings.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 305a7adc29a0ab94e9c01c35d9975a01 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/NetworkedGameSetup.prefab b/Assets/Prefabs/NetworkedGameSetup.prefab new file mode 100644 index 0000000..c66e996 --- /dev/null +++ b/Assets/Prefabs/NetworkedGameSetup.prefab @@ -0,0 +1,68 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &4905596560188172618 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2120591286217292487} + - component: {fileID: 9026571847668357918} + - component: {fileID: 3790448570997958578} + m_Layer: 0 + m_Name: NetworkedGameSetup + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2120591286217292487 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4905596560188172618} + serializedVersion: 2 + 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: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &9026571847668357918 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4905596560188172618} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d5a57f767e5e46a458fc5d3c628d0cbb, type: 3} + m_Name: + m_EditorClassIdentifier: + GlobalObjectIdHash: 1962602005 + AlwaysReplicateAsRoot: 0 + SynchronizeTransform: 1 + ActiveSceneSynchronization: 0 + SceneMigrationSynchronization: 1 + SpawnWithObservers: 1 + DontDestroyWithOwner: 0 + AutoObjectParentSync: 1 +--- !u!114 &3790448570997958578 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4905596560188172618} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 42a55d924c00a4749b9c44597675fd36, type: 3} + m_Name: + m_EditorClassIdentifier: + PlayerPrefab: {fileID: 3120938410244321186, guid: 29c8b8bbcf7287b4eb597729b2e0c9f9, type: 3} diff --git a/Assets/Prefabs/NetworkedGameSetup.prefab.meta b/Assets/Prefabs/NetworkedGameSetup.prefab.meta new file mode 100644 index 0000000..85f25f2 --- /dev/null +++ b/Assets/Prefabs/NetworkedGameSetup.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 056d6e4ea47c75e4d8ef3371fffe0315 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 9199710..3b70cd3 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -3478,24 +3478,72 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1536317696 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 2120591286217292487, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 4905596560188172618, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: m_Name + value: NetworkedGameSetup + objectReference: {fileID: 0} + - target: {fileID: 9026571847668357918, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} + propertyPath: GlobalObjectIdHash + value: 1962602005 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 056d6e4ea47c75e4d8ef3371fffe0315, type: 3} --- !u!1 &1566837117 stripped GameObject: m_CorrespondingSourceObject: {fileID: 809911508645467208, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} m_PrefabInstance: {fileID: 1683288374126251321} m_PrefabAsset: {fileID: 0} ---- !u!114 &1566837126 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1566837117} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 42a55d924c00a4749b9c44597675fd36, type: 3} - m_Name: - m_EditorClassIdentifier: - PlayerPrefab: {fileID: 0} --- !u!1 &1600052931 GameObject: m_ObjectHideFlags: 0 @@ -3693,13 +3741,25 @@ PrefabInstance: m_AddedComponents: - targetCorrespondingSourceObject: {fileID: 809911508645467208, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} insertIndex: -1 - addedObject: {fileID: 1566837126} + addedObject: {fileID: 1683288374126251323} m_SourcePrefab: {fileID: 100100000, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} --- !u!4 &1683288374126251322 stripped Transform: m_CorrespondingSourceObject: {fileID: 3032075919872812610, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} m_PrefabInstance: {fileID: 1683288374126251321} m_PrefabAsset: {fileID: 0} +--- !u!114 &1683288374126251323 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1566837117} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3e42fe7862f026640ac0a6b53663804e, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &4158834148864819266 PrefabInstance: m_ObjectHideFlags: 0 @@ -3714,7 +3774,7 @@ PrefabInstance: objectReference: {fileID: 5796191506433166634} - target: {fileID: 2404937059918327841, guid: 48e0e53445d42474895d37a321c39d1c, type: 3} propertyPath: m_AnchorMax.y - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 2458716502903188221, guid: 48e0e53445d42474895d37a321c39d1c, type: 3} propertyPath: rope @@ -3816,6 +3876,10 @@ PrefabInstance: propertyPath: m_Name value: UI objectReference: {fileID: 0} + - target: {fileID: 7301411897347746173, guid: 48e0e53445d42474895d37a321c39d1c, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] @@ -4759,6 +4823,7 @@ SceneRoots: m_ObjectHideFlags: 0 m_Roots: - {fileID: 1683288374126251321} + - {fileID: 1536317696} - {fileID: 4158834148864819266} - {fileID: 1600052934} - {fileID: 480860136} diff --git a/Assets/Scripts/Blood/BloodComputeShader.cs b/Assets/Scripts/Blood/BloodComputeShader.cs index cb9d296..e994b12 100644 --- a/Assets/Scripts/Blood/BloodComputeShader.cs +++ b/Assets/Scripts/Blood/BloodComputeShader.cs @@ -127,6 +127,8 @@ public class BloodComputeShader : MonoBehaviour // Update is called once per frame void Update() { + if (mop1 == null || mop2 == null) return; + bloodCompute.SetFloat("deltaTime", Time.deltaTime); bloodCompute.SetInt("numParticles", numParticles); bloodCompute.SetFloat("size", size); diff --git a/Assets/Scripts/Managers/AudioManager/AudioManager.cs b/Assets/Scripts/Managers/AudioManager/AudioManager.cs index 3c75511..2079480 100644 --- a/Assets/Scripts/Managers/AudioManager/AudioManager.cs +++ b/Assets/Scripts/Managers/AudioManager/AudioManager.cs @@ -23,8 +23,6 @@ public class AudioManager : MonoBehaviour { Destroy(this); } - - DontDestroyOnLoad(gameObject); } private void OnDisable() diff --git a/Assets/Scripts/Managers/Rumbling/RumbleManager.cs b/Assets/Scripts/Managers/Rumbling/RumbleManager.cs index 100a380..5a02faa 100644 --- a/Assets/Scripts/Managers/Rumbling/RumbleManager.cs +++ b/Assets/Scripts/Managers/Rumbling/RumbleManager.cs @@ -33,7 +33,7 @@ public class RumbleManager : MonoBehaviour if (Instance == null) { Instance = this; - DontDestroyOnLoad(gameObject); + //DontDestroyOnLoad(gameObject); for (int i = 0; i < Gamepad.all.Count; i++) { playerRumbles[i] = new List(); // Initialize list for each connected controller diff --git a/Assets/Scripts/Multiplayer/NetworkedGameSetup.cs b/Assets/Scripts/Multiplayer/NetworkedGameSetup.cs index b538805..36b3275 100644 --- a/Assets/Scripts/Multiplayer/NetworkedGameSetup.cs +++ b/Assets/Scripts/Multiplayer/NetworkedGameSetup.cs @@ -10,14 +10,18 @@ public class NetworkedGameSetup : NetworkBehaviour { [SerializeField] private GameObject PlayerPrefab; - private void Start() + private void Awake() { + if (NetworkManager.Singleton == null || NetworkManager.Singleton.SceneManager == null) return; + DontDestroyOnLoad(this); NetworkManager.Singleton.SceneManager.OnLoadEventCompleted += SceneLoaded; } private void SceneLoaded(string sceneName, LoadSceneMode loadSceneMode, List clientsCompleted, List clientsTimedOut) { + if (!sceneName.ToLower().Contains("game")) return; + NetworkManager.Singleton.SceneManager.OnLoadEventCompleted -= SceneLoaded; // Only run once StartSetupProcedure(clientsCompleted); } @@ -29,7 +33,12 @@ public class NetworkedGameSetup : NetworkBehaviour players = SpawnPlayers(playerIds); else players = GetPlayers(playerIds); + InitRope(players); + + InitUpgrader(players); + + InitBlood(players); } private GameObject[] GetPlayers(List playerIds) @@ -67,4 +76,19 @@ public class NetworkedGameSetup : NetworkBehaviour ropeSim.BuildRope(players[0].GetComponent(), players[1].GetComponent()); } + private void InitUpgrader(GameObject[] players) + { + Upgrader upgradeSystem = Upgrader.instance; + + upgradeSystem.player1 = players[0]; + upgradeSystem.player2 = players[1]; + } + + private void InitBlood(GameObject[] players) + { + BloodComputeShader bloodScript = BloodComputeShader.Instance; + + bloodScript.mop1 = players[0].GetComponent(); + bloodScript.mop2 = players[1].GetComponent(); + } } diff --git a/Assets/Scripts/Multiplayer/Project.Scripts.Multiplayer.asmdef b/Assets/Scripts/Multiplayer/Project.Scripts.Multiplayer.asmdef index b2be9ad..3550c75 100644 --- a/Assets/Scripts/Multiplayer/Project.Scripts.Multiplayer.asmdef +++ b/Assets/Scripts/Multiplayer/Project.Scripts.Multiplayer.asmdef @@ -9,7 +9,9 @@ "GUID:1491147abca9d7d4bb7105af628b223e", "GUID:75469ad4d38634e559750d17036d5f7c", "GUID:dfa0fc7c5444edd619a15e6f8c8f242a", - "GUID:42d1898a72cfe6848ae89835fb20acd2" + "GUID:42d1898a72cfe6848ae89835fb20acd2", + "GUID:ff1c299121c93f34ca827a253fc30a61", + "GUID:1eb4e3e6c04cdc848bab71651b1e2ecd" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Scripts/Player/Movement/PlayerMovement.cs b/Assets/Scripts/Player/Movement/PlayerMovement.cs index 46f215c..bdce55f 100644 --- a/Assets/Scripts/Player/Movement/PlayerMovement.cs +++ b/Assets/Scripts/Player/Movement/PlayerMovement.cs @@ -8,7 +8,6 @@ using UnityEngine.InputSystem.DualShock; [RequireComponent(typeof(PlayerInput))] public class PlayerMovement : MonoBehaviour { - public PlayerAnimationHandler animationHandler; public float moveSpeed = 5f; private Rigidbody2D rb; @@ -55,10 +54,10 @@ public class PlayerMovement : MonoBehaviour private void Update() { - if (playerInput.movement != Vector2.zero) - animationHandler.Run(true); - else - animationHandler.Run(false); + //if (playerInput.movement != Vector2.zero) + // animationHandler.Run(true); + //else + // animationHandler.Run(false); } private void FixedUpdate() diff --git a/Assets/Scripts/Upgrade/Upgrader.cs b/Assets/Scripts/Upgrade/Upgrader.cs index 6e9a9bf..5dc1808 100644 --- a/Assets/Scripts/Upgrade/Upgrader.cs +++ b/Assets/Scripts/Upgrade/Upgrader.cs @@ -63,6 +63,20 @@ public class Upgrader : MonoBehaviour public Image BloodMeter; public TMPro.TextMeshProUGUI description; + public static Upgrader instance; + + private void Awake() + { + if (instance == null) + { + instance = this; + } + else + { + Destroy(this); + } + } + // Start is called before the first frame update void Start() {