You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HighGroundRoyaleNetcode/Assets/Scripts/PlatformManager.cs

56 lines
1.9 KiB
C#

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