private void OnEnable() { // Kill other instances. First try FindObjectsOfType, then kill other singleton instance // For some reason, FindObjectsOfType ignores objects with non-standard HideFlags #if UNITY_EDITOR int maxInstances = (gameObject.hideFlags & HideFlags.DontSave) != 0 ? 0 : 1; #else const int maxInstances = 1; #endif if (FindObjectsOfType <ShadowManager>().Length > maxInstances) { DestroyImmediate(gameObject); return; } if (_instance != null && _instance != this) { DestroyImmediate(_instance.gameObject); } // Set yourself to be the active singleton instance _instance = this; _isDestroyed = false; Initialize(); #if UNITY_EDITOR UpdateCameraEvents(SceneView.GetAllSceneCameras(), HideFlags.DontSave); #endif }
private void OnDestroy() { if (_instance == this) { _instance = null; _isDestroyed = true; } Clear(); }
/// <summary> /// Sets up the manager. /// </summary> private void Initialize() { _instance = this; _isDestroyed = false; #if UNITY_EDITOR foreach (ShadowMeshManager meshManager in _meshManagers.Values) { meshManager.RecalculateGeometry(null); } #endif UpdateCameraEvents(); }