From 9ea479bf3277c324000d1be21066300f18baadb0 Mon Sep 17 00:00:00 2001 From: Hazim Bin Ijaz Date: Fri, 6 Dec 2024 17:06:29 +0500 Subject: [PATCH] Added platform entering logic --- ...tController_ArcherMysto.overrideController | 2 +- Assets/Scenes/BossRoom/DungeonEntrance.unity | 14 ++-- .../Gameplay/UserInput/ClientInputSender.cs | 5 +- Assets/Scripts/Platform.cs | 73 +++++++++++++++++++ Assets/Scripts/Platform.cs.meta | 11 +++ Assets/Scripts/PlatformManager.cs | 55 ++++++++++++++ Assets/Scripts/PlatformManager.cs.meta | 11 +++ ProjectSettings/TagManager.asset | 3 +- 8 files changed, 163 insertions(+), 11 deletions(-) create mode 100644 Assets/Scripts/Platform.cs create mode 100644 Assets/Scripts/Platform.cs.meta create mode 100644 Assets/Scripts/PlatformManager.cs create mode 100644 Assets/Scripts/PlatformManager.cs.meta diff --git a/Assets/Models/CharacterSetController_ArcherMysto.overrideController b/Assets/Models/CharacterSetController_ArcherMysto.overrideController index 3d11fc2..7c81f87 100644 --- a/Assets/Models/CharacterSetController_ArcherMysto.overrideController +++ b/Assets/Models/CharacterSetController_ArcherMysto.overrideController @@ -10,7 +10,7 @@ AnimatorOverrideController: m_Controller: {fileID: 9100000, guid: 81ba9d484ee6d174a8aeb3af411babc4, type: 2} m_Clips: - m_OriginalClip: {fileID: 1827226128182048838, guid: 2115c4661f55eff45a5a0f91fc0a12f0, type: 3} - m_OverrideClip: {fileID: -203655887218126122, guid: 7830a90682cdace4f91f2b986c3adb0e, type: 3} + m_OverrideClip: {fileID: -203655887218126122, guid: fbc8c4e2f62d94344bbd8cedef635f83, type: 3} - m_OriginalClip: {fileID: 6200578666267062213, guid: 2115c4661f55eff45a5a0f91fc0a12f0, type: 3} m_OverrideClip: {fileID: -203655887218126122, guid: 9e525bcba97d9fe48ad09c10ae3fe8b9, type: 3} - m_OriginalClip: {fileID: -3419257869308726280, guid: 2115c4661f55eff45a5a0f91fc0a12f0, type: 3} diff --git a/Assets/Scenes/BossRoom/DungeonEntrance.unity b/Assets/Scenes/BossRoom/DungeonEntrance.unity index 9b19f44..4bd41a1 100644 --- a/Assets/Scenes/BossRoom/DungeonEntrance.unity +++ b/Assets/Scenes/BossRoom/DungeonEntrance.unity @@ -135,7 +135,7 @@ GameObject: - component: {fileID: 240007732} - component: {fileID: 240007731} - component: {fileID: 240007730} - m_Layer: 0 + m_Layer: 12 m_Name: P (6) m_TagString: Untagged m_Icon: {fileID: 0} @@ -278,7 +278,7 @@ GameObject: - component: {fileID: 676920375} - component: {fileID: 676920374} - component: {fileID: 676920373} - m_Layer: 0 + m_Layer: 12 m_Name: P (2) m_TagString: Untagged m_Icon: {fileID: 0} @@ -383,7 +383,7 @@ GameObject: - component: {fileID: 849256362} - component: {fileID: 849256361} - component: {fileID: 849256360} - m_Layer: 0 + m_Layer: 12 m_Name: P (4) m_TagString: Untagged m_Icon: {fileID: 0} @@ -606,7 +606,7 @@ GameObject: - component: {fileID: 997499843} - component: {fileID: 997499842} - component: {fileID: 997499841} - m_Layer: 0 + m_Layer: 12 m_Name: P (7) m_TagString: Untagged m_Icon: {fileID: 0} @@ -711,7 +711,7 @@ GameObject: - component: {fileID: 1146060685} - component: {fileID: 1146060684} - component: {fileID: 1146060683} - m_Layer: 0 + m_Layer: 12 m_Name: P (1) m_TagString: Untagged m_Icon: {fileID: 0} @@ -922,7 +922,7 @@ GameObject: - component: {fileID: 1463337826} - component: {fileID: 1463337825} - component: {fileID: 1463337824} - m_Layer: 0 + m_Layer: 12 m_Name: P (3) m_TagString: Untagged m_Icon: {fileID: 0} @@ -1027,7 +1027,7 @@ GameObject: - component: {fileID: 1620155728} - component: {fileID: 1620155727} - component: {fileID: 1620155726} - m_Layer: 0 + m_Layer: 12 m_Name: P (5) m_TagString: Untagged m_Icon: {fileID: 0} diff --git a/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs b/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs index 89569ff..91e2e95 100644 --- a/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs +++ b/Assets/Scripts/Gameplay/UserInput/ClientInputSender.cs @@ -34,6 +34,7 @@ namespace Unity.BossRoom.Gameplay.UserInput LayerMask m_GroundLayerMask; LayerMask m_ActionLayerMask; + LayerMask m_PlatformLayerMask; const float k_MaxNavMeshDistance = 1f; @@ -153,7 +154,7 @@ namespace Unity.BossRoom.Gameplay.UserInput m_GroundLayerMask = LayerMask.GetMask(new[] { "Ground" }); m_ActionLayerMask = LayerMask.GetMask(new[] { "PCs", "NPCs", "Ground" }); - + m_PlatformLayerMask = LayerMask.GetMask(new[]{"Platform"}); m_RaycastHitComparer = new RaycastHitComparer(); } @@ -528,7 +529,7 @@ namespace Unity.BossRoom.Gameplay.UserInput if (Input.GetMouseButtonDown(0)) // Left-click to request swap { var ray = m_MainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition); - int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance, m_ActionLayerMask); + int hits = Physics.RaycastNonAlloc(ray, k_CachedHit, k_MouseInputRaycastDistance, m_PlatformLayerMask); if (hits > 0) { for (int i = 0; i < hits; i++) diff --git a/Assets/Scripts/Platform.cs b/Assets/Scripts/Platform.cs new file mode 100644 index 0000000..9e386ef --- /dev/null +++ b/Assets/Scripts/Platform.cs @@ -0,0 +1,73 @@ +using Unity.BossRoom.Gameplay.GameplayObjects.Character; +using UnityEngine; + +namespace Unity.Multiplayer.Samples.BossRoom +{ + [RequireComponent(typeof(Collider))] + public class Platform : MonoBehaviour + { + public bool IsOccupied => Occupier != null; + public ServerCharacter Occupier { get; private set; } + + private Collider m_PlatformCollider; + + private void Awake() + { + m_PlatformCollider = GetComponent(); + if (!m_PlatformCollider.isTrigger) + { + Debug.LogWarning($"Platform {name} collider must be set as a trigger."); + m_PlatformCollider.isTrigger = true; // Ensure it's a trigger. + } + } + + /// + /// Marks this platform as occupied by a specific player. + /// + /// The ServerCharacter occupying the platform. + public void Occupy(ServerCharacter player) + { + if (IsOccupied) + { + Debug.LogWarning($"Platform {name} is already occupied by {Occupier.name}."); + return; + } + + Occupier = player; + Debug.Log($"{player.name} has occupied Platform {name}."); + } + + /// + /// Clears the occupation of this platform. + /// + public void Vacate() + { + if (!IsOccupied) + { + Debug.LogWarning($"Platform {name} is not currently occupied."); + return; + } + + Debug.Log($"{Occupier.name} has vacated Platform {name}."); + Occupier = null; + } + + private void OnTriggerEnter(Collider other) + { + if (!IsOccupied && other.TryGetComponent(out var player)) + { + Occupy(player); + Debug.Log($"{player.name} has entered Platform {name}."); + } + } + + private void OnTriggerExit(Collider other) + { + if (IsOccupied && other.TryGetComponent(out var player) && player == Occupier) + { + Vacate(); + Debug.Log($"{player.name} has exited Platform {name}."); + } + } + } +} diff --git a/Assets/Scripts/Platform.cs.meta b/Assets/Scripts/Platform.cs.meta new file mode 100644 index 0000000..0a310d9 --- /dev/null +++ b/Assets/Scripts/Platform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fbadb65558c0b1a48b58b765317ed874 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlatformManager.cs b/Assets/Scripts/PlatformManager.cs new file mode 100644 index 0000000..b754ca1 --- /dev/null +++ b/Assets/Scripts/PlatformManager.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using System.Linq; +using Unity.BossRoom.Gameplay.GameplayObjects.Character; +using UnityEngine; + +namespace Unity.Multiplayer.Samples.BossRoom +{ + public class PlatformManager : MonoBehaviour + { + private List m_Platforms; + + private void Start() + { + m_Platforms = GetComponentsInChildren().ToList(); + } + + /// + /// Finds an unoccupied platform and assigns the player to it. + /// + /// The ServerCharacter to assign. + /// True if successfully assigned, false otherwise. + public bool AssignPlayerToPlatform(ServerCharacter player) + { + var platform = m_Platforms.FirstOrDefault(p => !p.IsOccupied); + if (platform != null) + { + platform.Occupy(player); + return true; + } + + Debug.LogWarning($"No unoccupied platforms available for {player.name}."); + return false; + } + + /// + /// Finds the platform currently occupied by the given player. + /// + /// The ServerCharacter to search for. + /// The platform occupied by the player, or null if not found. + public Platform GetPlatformOccupiedByPlayer(ServerCharacter player) + { + return m_Platforms.FirstOrDefault(p => p.Occupier == player); + } + + /// + /// Checks if a specific platform is occupied. + /// + /// The platform to check. + /// True if the platform is occupied, false otherwise. + public bool IsPlatformOccupied(Platform platform) + { + return platform.IsOccupied; + } + } +} diff --git a/Assets/Scripts/PlatformManager.cs.meta b/Assets/Scripts/PlatformManager.cs.meta new file mode 100644 index 0000000..edc4e9a --- /dev/null +++ b/Assets/Scripts/PlatformManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d9e826abe81bf7a4b88597fe93add614 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 77730a6..0b894a7 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -16,6 +16,7 @@ TagManager: - LightingRealtime - LightingProbes - LightingReflectionProbe + - Heavy layers: - Default - TransparentFX @@ -29,7 +30,7 @@ TagManager: - FloorSwitch - Environment - Debris - - + - Platform - - ExtraParticles - ExtraGeometry