using System.Linq; using UnityEngine; namespace Pumkin { /// /// Abstract class for making reload-proof singletons out of ScriptableObjects /// Returns the asset created on the editor, or creates one if it's missing /// Based on https://www.youtube.com/watch?v=VBA1QCoEAX4 /// /// Singleton type public abstract class SingletonScriptableObject : ScriptableObject where T : ScriptableObject { static T _instance = null; public static T Instance { get { if(!_instance) _instance = Resources.FindObjectsOfTypeAll().FirstOrDefault() ?? CreateInstance(); return _instance; } } } }