quantum-space-buddies/QSB/WorldSync/WorldObjectManager.cs

39 lines
843 B
C#
Raw Normal View History

2021-05-02 08:29:34 +00:00
using System.Collections.Generic;
2021-03-23 13:18:29 +00:00
using UnityEngine;
namespace QSB.WorldSync
{
public abstract class WorldObjectManager : MonoBehaviour
{
2021-03-25 22:01:10 +00:00
private static readonly List<WorldObjectManager> _managers = new List<WorldObjectManager>();
2021-03-23 13:18:29 +00:00
public static bool AllReady { get; private set; }
2021-03-25 22:01:10 +00:00
public virtual void Awake()
{
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
_managers.Add(this);
}
2021-03-23 13:18:29 +00:00
public virtual void OnDestroy()
{
QSBSceneManager.OnSceneLoaded -= OnSceneLoaded;
_managers.Remove(this);
}
private void OnSceneLoaded(OWScene scene, bool inUniverse)
=> AllReady = false;
2021-03-23 13:18:29 +00:00
public static void Rebuild(OWScene scene)
{
foreach (var manager in _managers)
{
manager.RebuildWorldObjects(scene);
}
AllReady = true;
2021-03-23 13:18:29 +00:00
}
protected abstract void RebuildWorldObjects(OWScene scene);
}
}