Created
December 14, 2017 16:52
-
-
Save Moe-Baker/052aac9e56d1cc8687160c430e003cf5 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
[CreateAssetMenu] | |
public class ManagerScriptableObject : ScriptableObject | |
{ | |
//variable will hold the instance value so we don't look for it everytime we need to access it | |
//access the Instance only via the Current Property | |
static ManagerScriptableObject _current; | |
public static ManagerScriptableObject Current | |
{ | |
get | |
{ | |
//check if null or if the application is not playing | |
//because we might've adedd an override so the current version could be invalid | |
if (_current == null || !Application.isPlaying) | |
_current = GetCurrent(); | |
return _current; | |
} | |
} | |
static ManagerScriptableObject GetCurrent() | |
{ | |
var list = Resources.LoadAll<ManagerScriptableObject>(""); | |
if (list.Length == 0) return null; | |
for (int i = 0; i < list.Length; i++) | |
{ | |
if (list[i].name.ToLower().Contains("override")) | |
return list[i]; | |
} | |
return list.First(); | |
} | |
//Is there a Current instance ? | |
public static bool AssetAvaliable { get { return Current != null; } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment