47 lines
927 B
C#
47 lines
927 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class WorldPauseManager : MonoBehaviour
|
|
{
|
|
public static WorldPauseManager Instance { get; private set; }
|
|
|
|
private readonly HashSet<IPauseable> pauseables = new HashSet<IPauseable>();
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
}
|
|
else
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|
|
public void Register(IPauseable pauseable)
|
|
{
|
|
if (pauseable != null) pauseables.Add(pauseable);
|
|
}
|
|
|
|
public void Unregister(IPauseable pauseable)
|
|
{
|
|
if (pauseable != null) pauseables.Remove(pauseable);
|
|
}
|
|
|
|
public void PauseWorld()
|
|
{
|
|
foreach (var p in pauseables)
|
|
{
|
|
p?.Pause();
|
|
}
|
|
}
|
|
|
|
public void ResumeWorld()
|
|
{
|
|
foreach (var p in pauseables)
|
|
{
|
|
p?.Resume();
|
|
}
|
|
}
|
|
} |