Added leveler
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public interface IPlayerInteractionSession
|
||||
{
|
||||
string ReleasePrompt { get; }
|
||||
bool IsControlledBy(ulong clientId);
|
||||
void RequestRelease();
|
||||
}
|
||||
|
||||
public static class PlayerInteractionSessionRegistry
|
||||
{
|
||||
private static readonly HashSet<IPlayerInteractionSession> Sessions = new();
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void ResetRegistry() => Sessions.Clear();
|
||||
|
||||
public static void Register(IPlayerInteractionSession session)
|
||||
{
|
||||
if (session != null)
|
||||
Sessions.Add(session);
|
||||
}
|
||||
|
||||
public static void Unregister(IPlayerInteractionSession session)
|
||||
{
|
||||
if (session != null)
|
||||
Sessions.Remove(session);
|
||||
}
|
||||
|
||||
public static bool TryGetControlledSession(
|
||||
ulong clientId,
|
||||
out IPlayerInteractionSession session)
|
||||
{
|
||||
foreach (IPlayerInteractionSession candidate in Sessions)
|
||||
{
|
||||
if (candidate != null && candidate.IsControlledBy(clientId))
|
||||
{
|
||||
session = candidate;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
session = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user