Skip to content

Instantly share code, notes, and snippets.

@ZeredaGames
Created April 9, 2019 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZeredaGames/75e26f26ff1ff5d6d5b5a46f12587d28 to your computer and use it in GitHub Desktop.
Save ZeredaGames/75e26f26ff1ff5d6d5b5a46f12587d28 to your computer and use it in GitHub Desktop.
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