From 23341177d9a80186762436c9067e13e8b7b2b7db Mon Sep 17 00:00:00 2001 From: Guillaume MORET <90462045+AyakorK@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:25:24 +0200 Subject: [PATCH 1/7] merge: Merge menu and develop and fix little issues (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * merge: Merge develop to menu (#9) * feat: Level move (#7) * feature: First try to add level move in Unity * feat: fix Arrow, upgrade door system * feat: Fix multiple problem * fix: fix door teleport with disable player public selected * feat: Addition of traps using sockets (#6) * feat: Add auto implementation from website of traps * chore: Add environment variables to UnityProject (#5) * fix: Remove useless Log that was crashed * fix(level_move): Replace hard-coded values ​​with variables for better flexibility Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Thomas Lamiable Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * feat: Add Socket to props to send them to back-end (#8) * feature: First try to add level move in Unity * feat: fix Arrow, upgrade door system * feat: Fix multiple problem * fix: fix door teleport with disable player public selected * feat: Addition of traps using sockets (#6) * feat: Add auto implementation from website of traps * chore: Add environment variables to UnityProject (#5) * fix: Remove useless Log that was crashed * feat: Add link to props using sockets * feat: Add a unique socket system manager --------- Co-authored-by: Thomas Lamiable --------- Co-authored-by: Thomas Lamiable Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix: Remove duplication of code * fix: Fix Idle animation --------- Co-authored-by: Thomas Lamiable Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .gitignore | 4 + Assets/Animations/Idle.anim | 9 +- Assets/Animations/Idle.anim.meta | 2 +- ...layerMovementAnimatorController.controller | 2 +- Assets/Prefabs/Player.prefab | 13 ++ .../RoomSystem/Corridor/CorridorX7.prefab | 13 ++ .../Prefabs/RoomSystem/Corridor/Room.prefab | 13 ++ Assets/Scenes/EmptyRoom_2.unity | 20 +- Assets/Scenes/TestRoom.unity | 216 ++++++++++++++---- Assets/Scripts/Map Control/DoorSystem.cs | 9 +- Assets/Scripts/Map Control/PropsSystem.cs | 120 ++++++++++ .../Scripts/Map Control/PropsSystem.cs.meta | 11 + Assets/Scripts/PlayerController.cs | 9 +- Assets/Scripts/SocketManager.cs | 53 +++++ Assets/Scripts/SocketManager.cs.meta | 11 + Assets/Scripts/Trap/TrapManager.cs | 109 +++++++-- Packages/manifest.json | 2 + Packages/packages-lock.json | 9 +- ProjectSettings/TagManager.asset | 1 + 19 files changed, 538 insertions(+), 88 deletions(-) create mode 100644 Assets/Scripts/Map Control/PropsSystem.cs create mode 100644 Assets/Scripts/Map Control/PropsSystem.cs.meta create mode 100644 Assets/Scripts/SocketManager.cs create mode 100644 Assets/Scripts/SocketManager.cs.meta diff --git a/.gitignore b/.gitignore index 7fbba8f6..33aba243 100644 --- a/.gitignore +++ b/.gitignore @@ -290,4 +290,8 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk + +# Environment file +.env + # End of https://www.toptal.com/developers/gitignore/api/macos,windows,linux,unity,intellij+all,clion+all \ No newline at end of file diff --git a/Assets/Animations/Idle.anim b/Assets/Animations/Idle.anim index c83538ba..8bbc33fe 100644 --- a/Assets/Animations/Idle.anim +++ b/Assets/Animations/Idle.anim @@ -72,11 +72,4 @@ AnimationClip: m_EulerEditorCurves: [] m_HasGenericRootTransform: 0 m_HasMotionFloatCurves: 0 - m_Events: - - time: 0 - functionName: - data: - objectReferenceParameter: {fileID: 0} - floatParameter: 0 - intParameter: 0 - messageOptions: 0 + m_Events: [] diff --git a/Assets/Animations/Idle.anim.meta b/Assets/Animations/Idle.anim.meta index dd9867ac..0e7f9204 100644 --- a/Assets/Animations/Idle.anim.meta +++ b/Assets/Animations/Idle.anim.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 35d46c531904e4f318de4b74f3406e3c +guid: 12864ee0eccb6402590333ee01067028 NativeFormatImporter: externalObjects: {} mainObjectFileID: 7400000 diff --git a/Assets/PlayerMovementAnimatorController.controller b/Assets/PlayerMovementAnimatorController.controller index 3a5b2554..36654f5c 100644 --- a/Assets/PlayerMovementAnimatorController.controller +++ b/Assets/PlayerMovementAnimatorController.controller @@ -74,7 +74,7 @@ AnimatorState: m_MirrorParameterActive: 0 m_CycleOffsetParameterActive: 0 m_TimeParameterActive: 0 - m_Motion: {fileID: 7400000, guid: 35d46c531904e4f318de4b74f3406e3c, type: 2} + m_Motion: {fileID: 7400000, guid: 12864ee0eccb6402590333ee01067028, type: 2} m_Tag: m_SpeedParameter: m_MirrorParameter: diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 7ead723c..112da2b0 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -14,6 +14,7 @@ GameObject: - component: {fileID: 1803017460098482366} - component: {fileID: 2136192976700920181} - component: {fileID: 2952415180134692435} + - component: {fileID: 7904266034163262073} m_Layer: 0 m_Name: Player m_TagString: Untagged @@ -212,3 +213,15 @@ PolygonCollider2D: - {x: 0.057479188, y: -0.12709153} - {x: 0.046700563, y: -0.12571843} m_UseDelaunayMesh: 0 +--- !u!114 &7904266034163262073 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1463738777561398421} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9d1d8695cfa6948278518a6a55e0b730, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Prefabs/RoomSystem/Corridor/CorridorX7.prefab b/Assets/Prefabs/RoomSystem/Corridor/CorridorX7.prefab index 4404662e..822ef877 100644 --- a/Assets/Prefabs/RoomSystem/Corridor/CorridorX7.prefab +++ b/Assets/Prefabs/RoomSystem/Corridor/CorridorX7.prefab @@ -1328,6 +1328,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 3022020511561805294} + - component: {fileID: 1349095506272017240} m_Layer: 0 m_Name: CorridorX7 m_TagString: Map @@ -1352,6 +1353,18 @@ Transform: - {fileID: 1238582843666978988} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1349095506272017240 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6369746937129949933} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9880ea29492da44c995f334244a5d19e, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &7452483412117750499 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/RoomSystem/Corridor/Room.prefab b/Assets/Prefabs/RoomSystem/Corridor/Room.prefab index 9852a198..7f06052a 100644 --- a/Assets/Prefabs/RoomSystem/Corridor/Room.prefab +++ b/Assets/Prefabs/RoomSystem/Corridor/Room.prefab @@ -2254,6 +2254,7 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 3176463435939833076} + - component: {fileID: 3498959641617480557} m_Layer: 0 m_Name: Room m_TagString: Map @@ -2278,6 +2279,18 @@ Transform: - {fileID: 8436259702988649751} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &3498959641617480557 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6459706332820108789} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9880ea29492da44c995f334244a5d19e, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &8327367539400217474 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/EmptyRoom_2.unity b/Assets/Scenes/EmptyRoom_2.unity index e698f038..35649546 100644 --- a/Assets/Scenes/EmptyRoom_2.unity +++ b/Assets/Scenes/EmptyRoom_2.unity @@ -122,7 +122,7 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &98536830 +--- !u!1 &6611451 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -130,10 +130,11 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 98536832} - - component: {fileID: 98536831} - m_Layer: 0 - m_Name: TrapManager + - component: {fileID: 6611452} + - component: {fileID: 6611454} + - component: {fileID: 6611453} + m_Layer: 5 + m_Name: Image m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -145,6 +146,7 @@ MonoBehaviour: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} +: {fileID: 1250698880} m_GameObject: {fileID: 98536830} m_Enabled: 1 m_EditorHideFlags: 0 @@ -630,8 +632,11 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 583d4dca14d33eb4094ca6f875781ab9, type: 3} + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 6459706332820108789, guid: 35bed5d2a54129845bcff6b3abaa746b, type: 3} + insertIndex: -1 + addedObject: {fileID: 791950512} + m_SourcePrefab: {fileID: 100100000, guid: 35bed5d2a54129845bcff6b3abaa746b, type: 3} --- !u!1001 &8803801296905376457 PrefabInstance: m_ObjectHideFlags: 0 @@ -760,3 +765,4 @@ SceneRoots: - {fileID: 8615776833325847340} - {fileID: 8803801296905376457} - {fileID: 1166055672053893236} + - {fileID: 1655521569} diff --git a/Assets/Scenes/TestRoom.unity b/Assets/Scenes/TestRoom.unity index cba86288..828c1cb0 100644 --- a/Assets/Scenes/TestRoom.unity +++ b/Assets/Scenes/TestRoom.unity @@ -132,6 +132,7 @@ GameObject: m_Component: - component: {fileID: 166584760} - component: {fileID: 166584759} + - component: {fileID: 166584761} m_Layer: 0 m_Name: Grid m_TagString: Untagged @@ -170,6 +171,18 @@ Transform: - {fileID: 542654705} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &166584761 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 166584758} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9880ea29492da44c995f334244a5d19e, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &371089590 GameObject: m_ObjectHideFlags: 0 @@ -184,7 +197,7 @@ GameObject: - component: {fileID: 371089592} m_Layer: 0 m_Name: Props - m_TagString: Untagged + m_TagString: Props m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -280,7 +293,7 @@ TilemapRenderer: m_LightmapParameters: {fileID: 0} m_SortingLayerID: 0 m_SortingLayer: 0 - m_SortingOrder: 2 + m_SortingOrder: 10 m_ChunkSize: {x: 32, y: 32, z: 32} m_ChunkCullingBounds: {x: 0, y: 0, z: 0} m_MaxChunkCount: 16 @@ -297,7 +310,77 @@ Tilemap: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 371089590} m_Enabled: 1 - m_Tiles: {} + m_Tiles: + - first: {x: 5, y: 4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 16 + m_TileSpriteIndex: 16 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: 6, y: 4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 15 + m_TileSpriteIndex: 15 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: 7, y: 4, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 14 + m_TileSpriteIndex: 14 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: 5, y: 5, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 13 + m_TileSpriteIndex: 13 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: 6, y: 5, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 12 + m_TileSpriteIndex: 12 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: 7, y: 5, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 11 + m_TileSpriteIndex: 11 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 + - first: {x: 7, y: 8, z: 0} + second: + serializedVersion: 2 + m_TileIndex: 17 + m_TileSpriteIndex: 17 + m_TileMatrixIndex: 0 + m_TileColorIndex: 0 + m_TileObjectToInstantiateIndex: 65535 + dummyAlignment: 0 + m_AllTileFlags: 1073741825 m_AnimatedTiles: {} m_TileAssetArray: - m_RefCount: 0 @@ -322,20 +405,20 @@ Tilemap: m_Data: {fileID: 0} - m_RefCount: 0 m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 20a107a89fc4a45e9a6943b56316bdb8, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 4b68c7dccf4024034a0e5bbf76946e58, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 64041abb85b474ca8bc6ac42116f1a85, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 6b71a2339c12b42f4b7bd7a4b09b6034, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 51ca0b128c1864a00a6ad2934f8dd7dd, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: fb3afcb689bb1455094d893aa9ab5628, type: 2} + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: c121db5a25a0e412bb83365aa0c6f778, type: 2} m_TileSpriteArray: - m_RefCount: 0 m_Data: {fileID: 0} @@ -359,22 +442,22 @@ Tilemap: m_Data: {fileID: 0} - m_RefCount: 0 m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} + - m_RefCount: 1 + m_Data: {fileID: -1457016805, guid: ad684922a8aff654ebccc527594e7603, type: 3} + - m_RefCount: 1 + m_Data: {fileID: 1866999083, guid: ad684922a8aff654ebccc527594e7603, type: 3} + - m_RefCount: 1 + m_Data: {fileID: -2127686085, guid: ad684922a8aff654ebccc527594e7603, type: 3} + - m_RefCount: 1 + m_Data: {fileID: 2105632713, guid: ad684922a8aff654ebccc527594e7603, type: 3} + - m_RefCount: 1 + m_Data: {fileID: -1052406375, guid: ad684922a8aff654ebccc527594e7603, type: 3} + - m_RefCount: 1 + m_Data: {fileID: 1681623567, guid: ad684922a8aff654ebccc527594e7603, type: 3} + - m_RefCount: 1 + m_Data: {fileID: 1026215578, guid: ad684922a8aff654ebccc527594e7603, type: 3} m_TileMatrixArray: - - m_RefCount: 0 + - m_RefCount: 7 m_Data: e00: 1 e01: 0 @@ -393,13 +476,13 @@ Tilemap: e32: 0 e33: 1 m_TileColorArray: - - m_RefCount: 0 + - m_RefCount: 7 m_Data: {r: 1, g: 1, b: 1, a: 1} m_TileObjectToInstantiateArray: [] m_AnimationFrameRate: 1 m_Color: {r: 1, g: 1, b: 1, a: 1} m_Origin: {x: 0, y: 0, z: 0} - m_Size: {x: 9, y: 7, z: 1} + m_Size: {x: 9, y: 9, z: 1} m_TileAnchor: {x: 0.5, y: 0.5, z: 0} m_TileOrientation: 0 m_TileOrientationMatrix: @@ -988,8 +1071,8 @@ Tilemap: - first: {x: 1, y: 4, z: 0} second: serializedVersion: 2 - m_TileIndex: 16 - m_TileSpriteIndex: 15 + m_TileIndex: 15 + m_TileSpriteIndex: 16 m_TileMatrixIndex: 0 m_TileColorIndex: 0 m_TileObjectToInstantiateIndex: 65535 @@ -1457,9 +1540,9 @@ Tilemap: m_Data: {fileID: 0} - m_RefCount: 0 m_Data: {fileID: 0} - - m_RefCount: 0 - m_Data: {fileID: 0} - - m_RefCount: 40 + - m_RefCount: 1 + m_Data: {fileID: 11400000, guid: 6d8f4121c2ddc4126ab09a32de00e2a6, type: 2} + - m_RefCount: 39 m_Data: {fileID: 11400000, guid: 8b2babf76b74e4944a6bb0895e3d4647, type: 2} - m_RefCount: 41 m_Data: {fileID: 11400000, guid: dcca059947b4d724f90a78f2915a478b, type: 2} @@ -1494,10 +1577,10 @@ Tilemap: m_Data: {fileID: 0} - m_RefCount: 0 m_Data: {fileID: 0} - - m_RefCount: 40 + - m_RefCount: 39 m_Data: {fileID: 92044262, guid: 3ef9fd33020450a4c845f8e9166d5558, type: 3} - - m_RefCount: 0 - m_Data: {fileID: 0} + - m_RefCount: 1 + m_Data: {fileID: 976511200, guid: ad684922a8aff654ebccc527594e7603, type: 3} - m_RefCount: 41 m_Data: {fileID: -1574383922, guid: 3ef9fd33020450a4c845f8e9166d5558, type: 3} m_TileMatrixArray: @@ -2814,6 +2897,54 @@ Tilemap: e31: 0 e32: 0 e33: 1 +--- !u!1 &1314584499 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1314584501} + - component: {fileID: 1314584500} + m_Layer: 0 + m_Name: TrapManager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1314584500 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1314584499} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3e906695758a3d04197ddceb298f6c86, type: 3} + m_Name: + m_EditorClassIdentifier: + trapPrefabs: + - {fileID: 6097000079642511365, guid: 127c53d14a0062f41a16963a87a85dc5, type: 3} + - {fileID: 7646078152559978388, guid: 40bc1f37707e62f4297f85bf5c7b01b4, type: 3} + - {fileID: 6762149095286452822, guid: d7c2a5ac1f23afe428f872343ed56d71, type: 3} +--- !u!4 &1314584501 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1314584499} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: -0.21531442, y: 0.33767503, z: 0.020564094} + 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!1 &1621253959 GameObject: m_ObjectHideFlags: 0 @@ -3460,6 +3591,7 @@ SceneRoots: m_ObjectHideFlags: 0 m_Roots: - {fileID: 519420032} + - {fileID: 1314584501} - {fileID: 619394802} - {fileID: 647252271} - {fileID: 166584760} diff --git a/Assets/Scripts/Map Control/DoorSystem.cs b/Assets/Scripts/Map Control/DoorSystem.cs index 3b891b82..5a27bd34 100644 --- a/Assets/Scripts/Map Control/DoorSystem.cs +++ b/Assets/Scripts/Map Control/DoorSystem.cs @@ -6,13 +6,11 @@ public class RoomManager : MonoBehaviour { - - // public DialogueManager dialogueManager; public GameObject newRoomPrefab; // Le prefab de la nouvelle pièce à générer private Transform player; // Le joueur à téléporter private GameObject currentRoom; // La pièce actuelle - private void Start() + private void Start() { // Trouver le joueur au début, en supposant qu'il a le tag "Player" GameObject playerObject = GameObject.FindGameObjectWithTag("Player"); @@ -34,7 +32,8 @@ private void OnTriggerEnter2D(Collider2D other) // dialogueManager.DisplayDialogue(null, "Salut ! Bagarre", "Talios"); currentRoom = GameObject.FindGameObjectWithTag("Map"); DeleteCurrentRoom(); - GameObject newRoom = Instantiate(newRoomPrefab, new Vector3(4.1f,2.8f,0.0f), Quaternion.identity); + Vector3 newRoomPosition = new Vector3(4.1f, 2.8f, 0.0f); + GameObject newRoom = Instantiate(newRoomPrefab, newRoomPosition, Quaternion.identity); PlacePlayerInNewRoom(newRoom); currentRoom = newRoom; } @@ -48,7 +47,7 @@ void PlacePlayerInNewRoom(GameObject newRoom) { Transform spawnPoint = newRoom.transform.Find("SpawnPoint"); - bool test = newRoom.transform.Find("SpawnPoint"); + bool test = newRoom.transform.Find("SpawnPoint"); Vector3 spawnPosition = spawnPoint.position; player.position = spawnPosition; //GameObject spawnPointObject = GameObject.FindWithTag("Respawn"); diff --git a/Assets/Scripts/Map Control/PropsSystem.cs b/Assets/Scripts/Map Control/PropsSystem.cs new file mode 100644 index 00000000..bb7175f8 --- /dev/null +++ b/Assets/Scripts/Map Control/PropsSystem.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.Tilemaps; +using SocketIOClient; +using CandyCoded.env; + +public class PropsManager : MonoBehaviour +{ + private Tilemap propsTilemap; // Reference to the Tilemap component + private SocketIOUnity clientSocket; + private bool PropsSent = false; + + private void Start() + { + clientSocket = SocketManager.Instance.ClientSocket; + InvokeRepeating(nameof(CheckSocketAndSendProps), 0f, 5f); // Check connection every 5 seconds + } + + // Check if the socket is connected before sending props + private async void CheckSocketAndSendProps() + { + Debug.Log("Checking socket connection..."); + + if (!PropsSent && clientSocket != null && clientSocket.Connected) + { + await FindAndSendProps(); + } + else + { + Debug.LogWarning("Socket not connected, skipping props send."); + } + } + + // Find the grid and the props tilemap, then send props positions to the server + private async Task FindAndSendProps() + { + GameObject grid = GameObject.Find("Grid"); + + if (grid != null) + { + propsTilemap = grid.transform.Find("Props")?.GetComponent(); + + if (propsTilemap != null) + { + List propsPositions = GetPropsPositions(); + + if (propsPositions.Count > 0) + { + List propsPositionsString = ConvertPositionsToString(propsPositions); + await EmitPropsToServer(propsPositionsString); + + CancelInvoke(nameof(CheckSocketAndSendProps)); // Stop repeating checks after sending + } + } + else + { + Debug.LogError("Props Tilemap not found in Grid!"); + } + } + else + { + Debug.LogError("Grid object not found!"); + } + } + + // Get all positions where there are props on the Tilemap + private List GetPropsPositions() + { + BoundsInt bounds = propsTilemap.cellBounds; + List propsPositions = new List(); + + for (int x = bounds.xMin; x < bounds.xMax; x++) + { + for (int y = bounds.yMin; y < bounds.yMax; y++) + { + Vector3Int tilePosition = new Vector3Int(x, y, 0); + + if (propsTilemap.HasTile(tilePosition)) + { + propsPositions.Add(tilePosition); + } + } + } + + Debug.Log($"Total props found: {propsPositions.Count}"); + return propsPositions; + } + + // Convert Vector3 positions to strings + private List ConvertPositionsToString(List propsPositions) + { + List propsPositionsString = new List(); + + foreach (Vector3 position in propsPositions) + { + string positionString = $"{position.x}, {position.y}"; + propsPositionsString.Add(positionString); + } + + return propsPositionsString; + } + + // Emit the props positions to the server + private async Task EmitPropsToServer(List propsPositionsString) + { + try + { + Debug.Log("Emitting props to server..."); + await clientSocket.EmitAsync("rooms:create", propsPositionsString); + PropsSent = true; + Debug.Log("Props successfully sent to server."); + } + catch (Exception e) + { + Debug.LogError("Failed to emit props: " + e.Message); + } + } +} diff --git a/Assets/Scripts/Map Control/PropsSystem.cs.meta b/Assets/Scripts/Map Control/PropsSystem.cs.meta new file mode 100644 index 00000000..f3a0d26f --- /dev/null +++ b/Assets/Scripts/Map Control/PropsSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9880ea29492da44c995f334244a5d19e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index aae600c0..fdd58f08 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -3,6 +3,7 @@ using System.Text; using UnityEngine; using SocketIOClient; +using CandyCoded.env; public class PlayerMovement : MonoBehaviour { @@ -23,14 +24,14 @@ public class PlayerMovement : MonoBehaviour private Vector2 previousMovement = Vector2.zero; + private string socketUrl; async void Start() { try { - var uri = new Uri("http://localhost:3000"); - clientSocket = new SocketIOUnity(uri); - - await clientSocket.ConnectAsync(); + env.TryParseEnvironmentVariable("SOCKET_URL", out string socketUrl); + var uri = new Uri(socketUrl); + clientSocket = SocketManager.Instance.ClientSocket; animator = GetComponent(); } diff --git a/Assets/Scripts/SocketManager.cs b/Assets/Scripts/SocketManager.cs new file mode 100644 index 00000000..14eddfc6 --- /dev/null +++ b/Assets/Scripts/SocketManager.cs @@ -0,0 +1,53 @@ +using System; +using System.Threading.Tasks; +using UnityEngine; +using SocketIOClient; +using CandyCoded.env; + +public class SocketManager : MonoBehaviour +{ + private static SocketManager _instance; + public static SocketManager Instance => _instance; + + public SocketIOUnity ClientSocket { get; private set; } + + private void Awake() + { + if (_instance != null && _instance != this) + { + Destroy(this.gameObject); + } + else + { + _instance = this; + DontDestroyOnLoad(this.gameObject); // Keep the socket alive across scenes + SetupSocket().ConfigureAwait(false); // Ensure proper async handling + } + } + + private async Task SetupSocket() + { + try + { + env.TryParseEnvironmentVariable("SOCKET_URL", out string socketUrl); + var uri = new Uri(socketUrl); + ClientSocket = new SocketIOUnity(uri); + + // Connect to the server + await ClientSocket.ConnectAsync(); + Debug.Log("Connected to backend via SocketManager."); + } + catch (Exception e) + { + Debug.LogError("Socket connection error: " + e.Message); + } + } + + private void OnApplicationQuit() + { + if (ClientSocket != null) + { + ClientSocket.Dispose(); // Properly close the connection + } + } +} diff --git a/Assets/Scripts/SocketManager.cs.meta b/Assets/Scripts/SocketManager.cs.meta new file mode 100644 index 00000000..7f14c6f6 --- /dev/null +++ b/Assets/Scripts/SocketManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d1d8695cfa6948278518a6a55e0b730 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Trap/TrapManager.cs b/Assets/Scripts/Trap/TrapManager.cs index 4fb5169a..329f7df5 100644 --- a/Assets/Scripts/Trap/TrapManager.cs +++ b/Assets/Scripts/Trap/TrapManager.cs @@ -1,62 +1,133 @@ +using System; using System.Collections; using System.Collections.Generic; -using System.Diagnostics; using UnityEngine; +using SocketIOClient; +using Newtonsoft.Json.Linq; +using CandyCoded.env; public class TrapManager : MonoBehaviour { - public List trapPrefabs = new List(); private Dictionary trapPrefabDictionary = new Dictionary(); private int gridSizeX = 9; private int gridSizeY = 9; private string[,] grid; + private Queue placementQueue = new Queue(); + private SocketIOUnity clientSocket; // SocketIO client + + private string socketUrl; + void Start() { - + // Initialize the grid grid = new string[gridSizeX, gridSizeY]; - + // Map trap names to their prefabs trapPrefabDictionary.Add("crossbow_down_prefab", trapPrefabs[0]); trapPrefabDictionary.Add("crossbow_up_prefab", trapPrefabs[1]); trapPrefabDictionary.Add("crossbow_side_prefab", trapPrefabs[2]); - // Exemple - SpawnTrapAtPosition(3, 5, "crossbow_down_prefab"); + // Set up Socket.IO client + StartCoroutine(ProcessPlacementQueue()); } + public void Update() + { + clientSocket = SocketManager.Instance.ClientSocket; + + clientSocket.On("traps:place", response => + { + JArray trapDataArray = JArray.Parse(response.ToString()); + + foreach (var trapData in trapDataArray) + { + JObject trap = (JObject)trapData["trap"]; - public void SpawnTrapAtPosition(int x, int y, string trapType) + int x = trap["x"].Value(); + int y = trap["y"].Value(); + string trapType = trap["trapType"].Value(); + + EnqueuePlacementOrder(x, y, trapType); + } + }); + } + + private void EnqueuePlacementOrder(int x, int y, string trapType) { + placementQueue.Enqueue(new TrapPlacement(x, y, trapType)); + } + private IEnumerator ProcessPlacementQueue() + { + while (true) + { + if (placementQueue.Count > 0) + { + TrapPlacement placement = placementQueue.Dequeue(); + SpawnTrapAtPosition(placement.x, placement.y, placement.trapType); + } + + yield return null; // Wait for the next frame + } + } + + private void SpawnTrapAtPosition(int x, int y, string trapType) + { + + // Check if the coordinates are valid and the spot is not occupied if (x >= 0 && x < gridSizeX && y >= 0 && y < gridSizeY && grid[x, y] == null) { - - if (trapPrefabDictionary.ContainsKey(trapType)) + + // Check if the trap type exists in the dictionary + if (trapPrefabDictionary.TryGetValue(trapType, out GameObject prefabToSpawn)) { - GameObject prefabToSpawn = trapPrefabDictionary[trapType]; + if (prefabToSpawn != null) + { - Vector3 spawnPosition = new Vector3(x, y, 0); - Instantiate(prefabToSpawn, spawnPosition, Quaternion.identity); + // Instantiate the prefab at the calculated position + Vector3 spawnPosition = new Vector3(x, y, 0); + GameObject spawnedTrap = Instantiate(prefabToSpawn, spawnPosition, Quaternion.identity); - - grid[x, y] = trapType; + // Mark the grid spot as occupied + grid[x, y] = trapType; + } + else + { + Debug.LogError($"Prefab for '{trapType}' is null! Check if the prefab is correctly assigned in the Inspector."); + } } else { - UnityEngine.Debug.LogWarning($"Le type de prefab '{trapType}' n'existe pas."); + Debug.LogWarning($"The trap type '{trapType}' does not exist in the dictionary."); } } else { - UnityEngine.Debug.LogWarning($"Position ({x}, {y}) est d�j� occup�e ou hors de la grille."); + Debug.LogWarning($"Position ({x}, {y}) is either occupied or out of bounds."); } } - public void ReceivePlacementOrder(int x, int y, string trapType) + void OnApplicationQuit() { - // M�thode pour recevoir des commandes WebSocket et placer les pi�ges - SpawnTrapAtPosition(x, y, trapType); + if (clientSocket != null) + { + clientSocket.Dispose(); // Properly close the connection + } + } + + private class TrapPlacement + { + public int x; + public int y; + public string trapType; + + public TrapPlacement(int x, int y, string trapType) + { + this.x = x; + this.y = y; + this.trapType = trapType; + } } } diff --git a/Packages/manifest.json b/Packages/manifest.json index 209847d3..8c67d776 100644 --- a/Packages/manifest.json +++ b/Packages/manifest.json @@ -4,8 +4,10 @@ "com.unity.2d.animation": "9.1.2", "com.unity.2d.sprite": "1.0.0", "com.unity.2d.tilemap": "1.0.0", + "com.unity.nuget.newtonsoft-json": "3.2.1", "com.unity.textmeshpro": "3.0.9", "com.unity.ugui": "1.0.0", + "xyz.candycoded.env": "https://github.com/CandyCoded/env.git#v1.1.0", "com.unity.modules.ai": "1.0.0", "com.unity.modules.androidjni": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index d6e9c572..5b6f7321 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -86,7 +86,7 @@ }, "com.unity.nuget.newtonsoft-json": { "version": "3.2.1", - "depth": 1, + "depth": 0, "source": "registry", "dependencies": {}, "url": "https://packages.unity.com" @@ -120,6 +120,13 @@ "com.unity.modules.imgui": "1.0.0" } }, + "xyz.candycoded.env": { + "version": "https://github.com/CandyCoded/env.git#v1.1.0", + "depth": 0, + "source": "git", + "dependencies": {}, + "hash": "c6951bc02488dbe99f48509a9e289ee73c74acda" + }, "com.unity.modules.ai": { "version": "1.0.0", "depth": 0, diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index efde76ec..eed87517 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -8,6 +8,7 @@ TagManager: - Wall - Enemy - Map + - Props - Dialogue layers: - Default From 0bdef31db430493a07eee4609e676ac9a698ab26 Mon Sep 17 00:00:00 2001 From: AyakorK Date: Sun, 20 Oct 2024 16:00:35 +0200 Subject: [PATCH 2/7] revert: Revert changes from EmptyRoom that breaked doors --- Assets/Scenes/EmptyRoom_2.unity | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/Assets/Scenes/EmptyRoom_2.unity b/Assets/Scenes/EmptyRoom_2.unity index 35649546..e698f038 100644 --- a/Assets/Scenes/EmptyRoom_2.unity +++ b/Assets/Scenes/EmptyRoom_2.unity @@ -122,7 +122,7 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &6611451 +--- !u!1 &98536830 GameObject: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -130,11 +130,10 @@ GameObject: m_PrefabAsset: {fileID: 0} serializedVersion: 6 m_Component: - - component: {fileID: 6611452} - - component: {fileID: 6611454} - - component: {fileID: 6611453} - m_Layer: 5 - m_Name: Image + - component: {fileID: 98536832} + - component: {fileID: 98536831} + m_Layer: 0 + m_Name: TrapManager m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -146,7 +145,6 @@ MonoBehaviour: m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} -: {fileID: 1250698880} m_GameObject: {fileID: 98536830} m_Enabled: 1 m_EditorHideFlags: 0 @@ -632,11 +630,8 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: - - targetCorrespondingSourceObject: {fileID: 6459706332820108789, guid: 35bed5d2a54129845bcff6b3abaa746b, type: 3} - insertIndex: -1 - addedObject: {fileID: 791950512} - m_SourcePrefab: {fileID: 100100000, guid: 35bed5d2a54129845bcff6b3abaa746b, type: 3} + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 583d4dca14d33eb4094ca6f875781ab9, type: 3} --- !u!1001 &8803801296905376457 PrefabInstance: m_ObjectHideFlags: 0 @@ -765,4 +760,3 @@ SceneRoots: - {fileID: 8615776833325847340} - {fileID: 8803801296905376457} - {fileID: 1166055672053893236} - - {fileID: 1655521569} From ebfcd1b226b9e2fce3c5d653d81a376d724f2d79 Mon Sep 17 00:00:00 2001 From: AyakorK Date: Mon, 21 Oct 2024 10:52:12 +0200 Subject: [PATCH 3/7] feat: V1.0 of WaitingScreen --- Assets/Prefabs/RoomSystem/WaitingRoom.prefab | 47 +++++ .../RoomSystem/WaitingRoom.prefab.meta | 7 + Assets/Scripts/PlayerController.cs | 1 - Assets/Scripts/WaitingTrapper.cs | 178 ++++++++++++++++++ Assets/Scripts/WaitingTrapper.cs.meta | 11 ++ ProjectSettings/TagManager.asset | 1 + 6 files changed, 244 insertions(+), 1 deletion(-) create mode 100644 Assets/Prefabs/RoomSystem/WaitingRoom.prefab create mode 100644 Assets/Prefabs/RoomSystem/WaitingRoom.prefab.meta create mode 100644 Assets/Scripts/WaitingTrapper.cs create mode 100644 Assets/Scripts/WaitingTrapper.cs.meta diff --git a/Assets/Prefabs/RoomSystem/WaitingRoom.prefab b/Assets/Prefabs/RoomSystem/WaitingRoom.prefab new file mode 100644 index 00000000..0a82ebe1 --- /dev/null +++ b/Assets/Prefabs/RoomSystem/WaitingRoom.prefab @@ -0,0 +1,47 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6577988205983815687 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 4087357368593639579} + - component: {fileID: 8065234719190424100} + m_Layer: 0 + m_Name: WaitingRoom + m_TagString: Temporary + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &4087357368593639579 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6577988205983815687} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 11.687407, y: 6.3912716, z: -0.07103652} + 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 &8065234719190424100 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6577988205983815687} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 804016391dce0430d92408fa75348918, type: 3} + m_Name: + m_EditorClassIdentifier: + messageFont: {fileID: 12800000, guid: e3265ab4bf004d28a9537516768c1c75, type: 3} diff --git a/Assets/Prefabs/RoomSystem/WaitingRoom.prefab.meta b/Assets/Prefabs/RoomSystem/WaitingRoom.prefab.meta new file mode 100644 index 00000000..90014f85 --- /dev/null +++ b/Assets/Prefabs/RoomSystem/WaitingRoom.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 56b8e144977b94114b4eb95ac32bfe84 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index fdd58f08..d629db09 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -128,7 +128,6 @@ async void SendData(string channel, string data) try { await clientSocket.EmitAsync(channel, data); - Debug.Log("Data sent: " + $"{channel}|{data}"); } catch (Exception e) { diff --git a/Assets/Scripts/WaitingTrapper.cs b/Assets/Scripts/WaitingTrapper.cs new file mode 100644 index 00000000..130a5144 --- /dev/null +++ b/Assets/Scripts/WaitingTrapper.cs @@ -0,0 +1,178 @@ +using System; +using UnityEngine; +using UnityEngine.UI; +using SocketIOClient; +using CandyCoded.env; +using Newtonsoft.Json.Linq; +using System.Collections; + +public class WaitingTrapper : MonoBehaviour +{ + private SocketIOUnity clientSocket; + private bool gamePaused = true; + + private GameObject overlay; + private Text messageText; + private Text codeText; + + public Font messageFont; + public PlayerMovement playerMovement; + + private string roomCode; + private bool trapperJoined = false; + private bool codeChanged = false; + private bool coroutineStarted = false; + + void Start() + { + clientSocket = SocketManager.Instance.ClientSocket; + CreateOverlay(); + BlockPlayerMovement(); + RegisterSocketEvents(); + } + + private void RegisterSocketEvents() + { + clientSocket.On("trapper:join", _ => OnTrapperJoin()); + clientSocket.On("rooms:create", response => OnRoomCreate(response)); + } + + private void OnTrapperJoin() + { + Debug.Log("Trapper joined the room!"); + trapperJoined = true; + } + + private void OnRoomCreate(SocketIOResponse response) + { + Debug.Log("Room created!"); + JArray roomDataArray = JArray.Parse(response.ToString()); + roomCode = roomDataArray[0]["code"].Value(); + + if (!string.IsNullOrEmpty(roomCode)) + { + codeChanged = true; + } + } + + private void CopyRoomCodeToClipboard() + { + try + { + GUIUtility.systemCopyBuffer = roomCode; + Debug.Log("Room code copied to clipboard: " + roomCode); + } + catch (Exception e) + { + Debug.LogError("Failed to copy to clipboard: " + e.Message); + } + } + + private void CreateOverlay() + { + var canvasObject = CreateCanvas(); + overlay = CreateOverlayImage(canvasObject); + messageText = CreateTextObject(canvasObject, "Waiting for trapper to join...", 50, Color.red, new Vector2(0.5f, 0.5f)); + codeText = CreateTextObject(canvasObject, "Waiting for the room code...", 30, Color.white, new Vector2(0.5f, 0.1f)); + } + + private GameObject CreateCanvas() + { + var canvasObject = new GameObject("OverlayCanvas"); + var canvas = canvasObject.AddComponent(); + canvas.renderMode = RenderMode.ScreenSpaceOverlay; + canvasObject.AddComponent(); + return canvasObject; + } + + private GameObject CreateOverlayImage(GameObject parent) + { + var overlay = new GameObject("OverlayImage"); + overlay.transform.parent = parent.transform; + + var overlayImage = overlay.AddComponent(); + overlayImage.color = new Color(0, 0, 0, 0.8f); + + var overlayRect = overlay.GetComponent(); + overlayRect.anchorMin = Vector2.zero; + overlayRect.anchorMax = Vector2.one; + overlayRect.offsetMin = Vector2.zero; + overlayRect.offsetMax = Vector2.zero; + + return overlay; + } + + private Text CreateTextObject(GameObject parent, string text, int fontSize, Color color, Vector2 anchor) + { + var textObject = new GameObject(text + "Text"); + textObject.transform.parent = parent.transform; + var textComponent = textObject.AddComponent(); + textComponent.text = text; + textComponent.font = messageFont; + textComponent.fontSize = fontSize; + textComponent.color = color; + textComponent.alignment = TextAnchor.MiddleCenter; + + var textRect = textObject.GetComponent(); + textRect.anchorMin = anchor; + textRect.anchorMax = anchor; + textRect.sizeDelta = new Vector2(800, 200); + textRect.anchoredPosition = Vector2.zero; + + return textComponent; + } + + private void BlockPlayerMovement() + { + gamePaused = true; + if (playerMovement != null) + { + playerMovement.enabled = false; + } + } + + private void ResumePlayerMovement() + { + gamePaused = false; + if (playerMovement != null) + { + playerMovement.enabled = true; + } + Destroy(overlay.transform.parent.gameObject); + Destroy(this); + } + + private IEnumerator StartCountdown(int countdownTime) + { + while (countdownTime > 0) + { + Debug.Log("Countdown: " + countdownTime); + messageText.text = $"Trapper joined! Time to place traps: {countdownTime}s"; + yield return new WaitForSecondsRealtime(1); + countdownTime--; + } + ResumePlayerMovement(); + } + + void Update() + { + if (trapperJoined) + { + trapperJoined = false; // Reset the flag + coroutineStarted = true; + StartCoroutine(StartCountdown(5)); // Start countdown for traps + } + + if (gamePaused && !coroutineStarted) + { + messageText.text = "Waiting for trapper to join..."; + } + + if (codeChanged) + { + codeChanged = false; + codeText.text = $"Room Code: {roomCode} (copied to clipboard)"; + CopyRoomCodeToClipboard(); + } + } +} diff --git a/Assets/Scripts/WaitingTrapper.cs.meta b/Assets/Scripts/WaitingTrapper.cs.meta new file mode 100644 index 00000000..6154e7f6 --- /dev/null +++ b/Assets/Scripts/WaitingTrapper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 804016391dce0430d92408fa75348918 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index eed87517..76c2eac3 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -10,6 +10,7 @@ TagManager: - Map - Props - Dialogue + - Temporary layers: - Default - TransparentFX From b27be8de6f1689e83bc68851a4edff7d78587a63 Mon Sep 17 00:00:00 2001 From: AyakorK Date: Mon, 21 Oct 2024 12:53:45 +0200 Subject: [PATCH 4/7] fix: Fix the way of sending props and remove the SocketManager from the player --- Assets/Prefabs/Player.prefab | 13 ------------- Assets/Scripts/Map Control/PropsSystem.cs | 2 +- Assets/Scripts/UI/MainMenu.cs | 19 ++++++++++++++----- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Assets/Prefabs/Player.prefab b/Assets/Prefabs/Player.prefab index 112da2b0..7ead723c 100644 --- a/Assets/Prefabs/Player.prefab +++ b/Assets/Prefabs/Player.prefab @@ -14,7 +14,6 @@ GameObject: - component: {fileID: 1803017460098482366} - component: {fileID: 2136192976700920181} - component: {fileID: 2952415180134692435} - - component: {fileID: 7904266034163262073} m_Layer: 0 m_Name: Player m_TagString: Untagged @@ -213,15 +212,3 @@ PolygonCollider2D: - {x: 0.057479188, y: -0.12709153} - {x: 0.046700563, y: -0.12571843} m_UseDelaunayMesh: 0 ---- !u!114 &7904266034163262073 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1463738777561398421} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 9d1d8695cfa6948278518a6a55e0b730, type: 3} - m_Name: - m_EditorClassIdentifier: diff --git a/Assets/Scripts/Map Control/PropsSystem.cs b/Assets/Scripts/Map Control/PropsSystem.cs index bb7175f8..8521ec97 100644 --- a/Assets/Scripts/Map Control/PropsSystem.cs +++ b/Assets/Scripts/Map Control/PropsSystem.cs @@ -108,7 +108,7 @@ private async Task EmitPropsToServer(List propsPositionsString) try { Debug.Log("Emitting props to server..."); - await clientSocket.EmitAsync("rooms:create", propsPositionsString); + await clientSocket.EmitAsync("props:send", propsPositionsString); PropsSent = true; Debug.Log("Props successfully sent to server."); } diff --git a/Assets/Scripts/UI/MainMenu.cs b/Assets/Scripts/UI/MainMenu.cs index a0d691e6..d0fe65b9 100644 --- a/Assets/Scripts/UI/MainMenu.cs +++ b/Assets/Scripts/UI/MainMenu.cs @@ -7,15 +7,24 @@ public class MainMenu : MonoBehaviour { public string selectedScene; - public void QuitGame(){ + private SocketIOUnity clientSocket; - Application.Quit(); + + void Start() + { + clientSocket = SocketManager.Instance.ClientSocket; } - public void StartRoom(){ + public void QuitGame() + { + + Application.Quit(); + } - - SceneManager.LoadScene(selectedScene); + public async void StartRoom() + { + await clientSocket.EmitAsync("rooms:create"); + SceneManager.LoadScene(selectedScene); } } From 1948c54ffa14f699bd2310871db652de353c2a2d Mon Sep 17 00:00:00 2001 From: AyakorK Date: Mon, 21 Oct 2024 19:31:42 +0200 Subject: [PATCH 5/7] fix: Remove the Socket when leaving to the menu --- Assets/Scripts/UI/PauseMenu.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/UI/PauseMenu.cs b/Assets/Scripts/UI/PauseMenu.cs index f3bdf5b9..4f764d19 100644 --- a/Assets/Scripts/UI/PauseMenu.cs +++ b/Assets/Scripts/UI/PauseMenu.cs @@ -8,7 +8,8 @@ public class PauseMenu : MonoBehaviour public static bool gameIsPaused = false; public GameObject pauseMenuUI; - void Update(){ + void Update() + { if (Input.GetKeyDown(KeyCode.Escape)) { @@ -25,7 +26,8 @@ void Paused() gameIsPaused = true; } - public void Resume(){ + public void Resume() + { pauseMenuUI.SetActive(false); Time.timeScale = 1; gameIsPaused = false; @@ -34,10 +36,10 @@ public void Resume(){ public void LoadMainMenu() { Resume(); - GameObject player = GameObject.FindWithTag("Player"); - if (player != null) Destroy(player.gameObject); + GameObject socket = GameObject.FindWithTag("Temporary"); + if (socket != null) Destroy(socket.gameObject); SceneManager.LoadScene("Menu"); - + } } From a3a0ba734349a077a08bb1d4bf70c2f39a53f9b4 Mon Sep 17 00:00:00 2001 From: AyakorK Date: Tue, 22 Oct 2024 10:23:43 +0200 Subject: [PATCH 6/7] feat: Add the SocketManager to the Menu --- Assets/Scenes/UI/Menu.unity | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Assets/Scenes/UI/Menu.unity b/Assets/Scenes/UI/Menu.unity index 6bc4a72c..08557abb 100644 --- a/Assets/Scenes/UI/Menu.unity +++ b/Assets/Scenes/UI/Menu.unity @@ -921,6 +921,50 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1245127443 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1245127445} + - component: {fileID: 1245127444} + m_Layer: 0 + m_Name: Socket + m_TagString: Temporary + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1245127444 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1245127443} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9d1d8695cfa6948278518a6a55e0b730, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &1245127445 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1245127443} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 893.28735, y: -14.503334, z: -12.123516} + 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!1 &1332151914 GameObject: m_ObjectHideFlags: 0 @@ -1326,3 +1370,4 @@ SceneRoots: - {fileID: 1059973423} - {fileID: 2021776756} - {fileID: 1211020662} + - {fileID: 1245127445} From 242d414fb7e6d9a7d163cfa2e0d0c35de2f15331 Mon Sep 17 00:00:00 2001 From: AyakorK Date: Tue, 22 Oct 2024 10:34:19 +0200 Subject: [PATCH 7/7] fix: Fix player animation and options text --- Assets/PlayerMovementAnimatorController.controller | 8 ++++---- Assets/Scenes/UI/Menu.unity | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Assets/PlayerMovementAnimatorController.controller b/Assets/PlayerMovementAnimatorController.controller index 36654f5c..6da36e48 100644 --- a/Assets/PlayerMovementAnimatorController.controller +++ b/Assets/PlayerMovementAnimatorController.controller @@ -10,7 +10,7 @@ AnimatorStateTransition: m_Conditions: - m_ConditionMode: 3 m_ConditionEvent: MoveY - m_EventTreshold: -0.95 + m_EventTreshold: -0.2 m_DstStateMachine: {fileID: 0} m_DstState: {fileID: -6214595074649590134} m_Solo: 0 @@ -117,7 +117,7 @@ AnimatorStateTransition: m_Conditions: - m_ConditionMode: 4 m_ConditionEvent: MoveY - m_EventTreshold: 0.95 + m_EventTreshold: 0.2 m_DstStateMachine: {fileID: 0} m_DstState: {fileID: -6214595074649590134} m_Solo: 0 @@ -288,7 +288,7 @@ AnimatorStateTransition: m_Conditions: - m_ConditionMode: 3 m_ConditionEvent: MoveX - m_EventTreshold: -0.95 + m_EventTreshold: -0.7 m_DstStateMachine: {fileID: 0} m_DstState: {fileID: -6214595074649590134} m_Solo: 0 @@ -313,7 +313,7 @@ AnimatorStateTransition: m_Conditions: - m_ConditionMode: 4 m_ConditionEvent: MoveX - m_EventTreshold: 0.95 + m_EventTreshold: 0.7 m_DstStateMachine: {fileID: 0} m_DstState: {fileID: -6214595074649590134} m_Solo: 0 diff --git a/Assets/Scenes/UI/Menu.unity b/Assets/Scenes/UI/Menu.unity index 08557abb..957fefe7 100644 --- a/Assets/Scenes/UI/Menu.unity +++ b/Assets/Scenes/UI/Menu.unity @@ -1114,7 +1114,7 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: Option + m_Text: Options --- !u!222 &1333215637 CanvasRenderer: m_ObjectHideFlags: 0