using UnityEngine; namespace UltimateWater.Internal { public class ApplicationSingleton : MonoBehaviour where T : MonoBehaviour { private static T _Instance; private static bool _Quiting; public static T Instance { get { if (_Instance != null) { return _Instance; } _Instance = (T)Object.FindObjectOfType(typeof(T)); if (_Instance != null) { return _Instance; } if (_Quiting) { return (T)null; } GameObject gameObject = new GameObject("[" + typeof(T).Name + "] - instance"); gameObject.hideFlags = HideFlags.HideInHierarchy; GameObject gameObject2 = gameObject; Object.DontDestroyOnLoad(gameObject2); _Instance = gameObject2.AddComponent(); return _Instance; } } protected virtual void OnApplicationQuit() { _Quiting = true; } protected virtual void OnDestroy() { _Quiting = true; } } }