using System; using System.Collections.Generic; using System.Linq; using Unity.BossRoom.Gameplay.GameplayObjects.Character; using UnityEngine; namespace Unity.Multiplayer.Samples.BossRoom { public class PlatformManager : MonoBehaviour { public static PlatformManager Instance = null; private List m_Platforms; private void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } } private void Start() { m_Platforms = GetComponentsInChildren().ToList(); // Assign unique IDs to each platform for (int i = 0; i < m_Platforms.Count; i++) { m_Platforms[i].AssignID(i + 1); // IDs start from 1 } Debug.Log("All platforms have been assigned unique IDs."); } /// /// 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; } public Vector3 GetPlatformPosition(int platformId) { var platform = m_Platforms.FirstOrDefault(p => p.PlatformID == platformId); return platform ? platform.transform.position : Vector3.zero; } public Platform GetPlatformById(int platformId) { return m_Platforms.FirstOrDefault(p => p.PlatformID == platformId); } } }