private static void MakeSingleton(RootBehaviour instance) { UnityEnsure.Argument.NotNull(instance, nameof(instance)); foreach (var inst in _instances.Where(inst => inst != instance).ToArray()) { DestroyInstance(inst); } }
private void OnDestroy() { Instance = null; }
private void Awake() { MakeSingleton(this); Instance = this; }
private static void DestroyInstance(RootBehaviour inst) { UnityObjectUtil.Destroy(inst.gameObject); _instances.Remove(inst); }