Added platform entering logic

dev-ali
Hazim Bin Ijaz 6 days ago
parent 908cac3c95
commit 9ea479bf32

@ -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}

@ -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}

@ -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++)

@ -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<Collider>();
if (!m_PlatformCollider.isTrigger)
{
Debug.LogWarning($"Platform {name} collider must be set as a trigger.");
m_PlatformCollider.isTrigger = true; // Ensure it's a trigger.
}
}
/// <summary>
/// Marks this platform as occupied by a specific player.
/// </summary>
/// <param name="player">The ServerCharacter occupying the platform.</param>
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}.");
}
/// <summary>
/// Clears the occupation of this platform.
/// </summary>
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<ServerCharacter>(out var player))
{
Occupy(player);
Debug.Log($"{player.name} has entered Platform {name}.");
}
}
private void OnTriggerExit(Collider other)
{
if (IsOccupied && other.TryGetComponent<ServerCharacter>(out var player) && player == Occupier)
{
Vacate();
Debug.Log($"{player.name} has exited Platform {name}.");
}
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fbadb65558c0b1a48b58b765317ed874
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -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<Platform> m_Platforms;
private void Start()
{
m_Platforms = GetComponentsInChildren<Platform>().ToList();
}
/// <summary>
/// Finds an unoccupied platform and assigns the player to it.
/// </summary>
/// <param name="player">The ServerCharacter to assign.</param>
/// <returns>True if successfully assigned, false otherwise.</returns>
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;
}
/// <summary>
/// Finds the platform currently occupied by the given player.
/// </summary>
/// <param name="player">The ServerCharacter to search for.</param>
/// <returns>The platform occupied by the player, or null if not found.</returns>
public Platform GetPlatformOccupiedByPlayer(ServerCharacter player)
{
return m_Platforms.FirstOrDefault(p => p.Occupier == player);
}
/// <summary>
/// Checks if a specific platform is occupied.
/// </summary>
/// <param name="platform">The platform to check.</param>
/// <returns>True if the platform is occupied, false otherwise.</returns>
public bool IsPlatformOccupied(Platform platform)
{
return platform.IsOccupied;
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d9e826abe81bf7a4b88597fe93add614
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -16,6 +16,7 @@ TagManager:
- LightingRealtime
- LightingProbes
- LightingReflectionProbe
- Heavy
layers:
- Default
- TransparentFX
@ -29,7 +30,7 @@ TagManager:
- FloorSwitch
- Environment
- Debris
-
- Platform
-
- ExtraParticles
- ExtraGeometry

Loading…
Cancel
Save