Guest User

Untitled

a guest
Dec 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. [CreateAssetMenu]
  2. public class ManagerScriptableObject : ScriptableObject
  3. {
  4. //variable will hold the instance value so we don't look for it everytime we need to access it
  5. //access the Instance only via the Current Property
  6. static ManagerScriptableObject _current;
  7. public static ManagerScriptableObject Current
  8. {
  9. get
  10. {
  11. //check if null or if the application is not playing
  12. //because we might've adedd an override so the current version could be invalid
  13. if (_current == null || !Application.isPlaying)
  14. _current = GetCurrent();
  15.  
  16. return _current;
  17. }
  18. }
  19. static ManagerScriptableObject GetCurrent()
  20. {
  21. var list = Resources.LoadAll<ManagerScriptableObject>("");
  22.  
  23. if (list.Length == 0) return null;
  24.  
  25. for (int i = 0; i < list.Length; i++)
  26. {
  27. if (list[i].name.ToLower().Contains("override"))
  28. return list[i];
  29. }
  30.  
  31. return list.First();
  32. }
  33.  
  34. //Is there a Current instance ?
  35. public static bool AssetAvaliable { get { return Current != null; } }
  36. }
Add Comment
Please, Sign In to add comment