Last active
March 26, 2019 16:38
-
-
Save ciwolsey/3bd0189a8bbc76e3f7242b51473ff3f6 to your computer and use it in GitHub Desktop.
Singleton Scriptable Object (Unity)
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
using UnityEngine; | |
// Singleton Scriptable Object | |
// Rename "OptionsSO" to something more appropriate | |
public class OptionsSO : ScriptableObject | |
{ | |
// Scriptable Object Data | |
public enum Difficulty { Easy, Medium, Hard }; | |
public Difficulty difficulty = Difficulty.Easy; | |
// Callbacks | |
private void OnEnable() | |
{ | |
} | |
private void OnDisable() | |
{ | |
} | |
private void OnDestroy() | |
{ | |
} | |
// Singleton pattern | |
private static OptionsSO _inst; | |
public static OptionsSO Instance | |
{ | |
get | |
{ | |
if (!_inst) | |
_inst = FindObjectOfType<OptionsSO>(); | |
if (!_inst) | |
{ | |
_inst = CreateInstance<OptionsSO>(); | |
_inst.hideFlags = HideFlags.DontUnloadUnusedAsset; | |
} | |
return _inst; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment