quantum-space-buddies/QSB/WorldSync/WorldObjectManager.cs
2021-06-19 11:26:05 +01:00

40 lines
843 B
C#

using System.Collections.Generic;
using UnityEngine;
namespace QSB.WorldSync
{
public abstract class WorldObjectManager : MonoBehaviour
{
private static readonly List<WorldObjectManager> _managers = new List<WorldObjectManager>();
public static bool AllReady { get; private set; }
public virtual void Awake()
{
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
_managers.Add(this);
}
public virtual void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
_managers.Remove(this);
}
private void OnSceneLoaded(OWScene scene, bool inUniverse)
=> AllReady = false;
public static void Rebuild(OWScene scene)
{
foreach (var manager in _managers)
{
manager.RebuildWorldObjects(scene);
}
AllReady = true;
}
protected abstract void RebuildWorldObjects(OWScene scene);
}
}