Created
April 9, 2019 21:43
-
-
Save ZeredaGames/75e26f26ff1ff5d6d5b5a46f12587d28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Awake(){ | |
AwakeSingleton(); | |
} | |
#region Internal Singleton | |
[Header("Internal Singleton:"), Tooltip("If True: this becomes a singleton.")] | |
public bool SetDontDestroyOnLoad = true; | |
public bool DebugMode = true; | |
/// <summary> | |
/// The instance of this script. | |
/// </summary> | |
public static MyScript Instance; | |
/// <summary> | |
/// In Case you wanted to call StartCoroutine in a static method | |
/// </summary> | |
public static MonoBehaviour monoBehaviour; | |
public void AwakeSingleton() | |
{ | |
// if the singleton hasn't been initialized yet | |
if (Equals(SetDontDestroyOnLoad, true)) | |
{ | |
if (!Equals(Instance, null) && !Equals(Instance, this)) | |
{ | |
if (Instance.DebugMode) | |
Debug.LogError("Duplicate singleton " + this.gameObject + " created; destroying it now"); | |
Destroy(gameObject); | |
} | |
else { | |
DontDestroyOnLoad(gameObject); | |
} | |
} | |
else { | |
Instance = this; | |
monoBehaviour = GetComponent<MonoBehaviour>(); | |
} | |
OnSetDebugMode = DebugMode; | |
} | |
public static bool OnSetDebugMode { | |
set { | |
PlayerPrefsManagerMain.SetString ("DebugMode", DebugMode.ToString ()); | |
DebugMode = value; | |
} | |
} | |
public bool GetGebugMode{ | |
get{ | |
string message = PlayerPrefsManagerMain.GetString ("DebugMode"; | |
if(message == "true"){ | |
DebugMode = true; | |
} else { | |
DebugMode = false; | |
} | |
} | |
} | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment