otamesi
This commit is contained in:
47
Assets/_Scripts/WorldPauseService.cs
Normal file
47
Assets/_Scripts/WorldPauseService.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user