diff --git a/Runtime/Singleton.cs b/Runtime/Singleton.cs index 9bd45b6..101362e 100644 --- a/Runtime/Singleton.cs +++ b/Runtime/Singleton.cs @@ -5,13 +5,9 @@ namespace FishingCactus.CommonCode public class Singleton<_INSTANCE_> : MonoBehaviour where _INSTANCE_ : Singleton<_INSTANCE_> { - // -- FIELDS - - [SerializeField] private bool DestroyOnLoad = false; - private static _INSTANCE_ _instance = null; - // -- PROPERTIES + [SerializeField] private bool DestroyOnLoad = false; public static _INSTANCE_ Instance { @@ -28,7 +24,12 @@ public static _INSTANCE_ Instance public static bool HasInstance => _instance != null; - // -- UNITY + public static bool TryGetInstance( out _INSTANCE_ instance ) + { + instance = Instance; + + return instance != null; + } public virtual void Awake() { @@ -43,10 +44,10 @@ public virtual void Awake() } else if( _instance != this ) { - Debug.LogError( $"{_instance.name} is added two times.", this ); + Debug.LogWarning( $"There are two instances of {_instance.name}. The latest one will be destroyed.", _instance ); Destroy( this ); } } } -} \ No newline at end of file +}