Skip to content

Instantly share code, notes, and snippets.

@Moe-Baker
Created December 14, 2017 16:52
Show Gist options
  • Save Moe-Baker/052aac9e56d1cc8687160c430e003cf5 to your computer and use it in GitHub Desktop.
Save Moe-Baker/052aac9e56d1cc8687160c430e003cf5 to your computer and use it in GitHub Desktop.
[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