47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
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;
|
|
}
|
|
}
|