void Awake() { if (Application.isPlaying) { gameObject.hideFlags = HideFlags.HideInHierarchy; DontDestroyOnLoad(gameObject); } // There can be only one! if (instance != null && instance != this) { GameObject.Destroy(instance); instance = this; } }
void OnDestroy() { #if UNITY_EDITOR if (PlaymodeListener.IsQuitingPlaymode) { return; } #endif // make sure we have somebody to continue our job if we get destroyed if (instance != this) { return; } instance = FindObjectOfType <InvokerProxyLate>(); if (instance != null) { return; } instance = new GameObject("Invoker").AddComponent <InvokerProxyLate>(); }
/// <summary> /// Assures there exists an instance of this type. /// </summary> public static void Touch() { if (instance != null) { return; } if (Thread.CurrentThread.ManagedThreadId != 1) { return; } if (!Application.isPlaying) { return; } instance = FindObjectOfType <InvokerProxyLate>(); if (instance != null) { return; } instance = new GameObject("Invoker").AddComponent <InvokerProxyLate>(); }