Files
Dpr-ScriptsOnly/Assets/SmartPoint/AssetAssistant/SingletonScriptableObject.cs

43 lines
1.1 KiB
C#
Raw Permalink Normal View History

2023-06-20 13:17:31 -05:00
using System;
2023-07-01 21:07:29 -05:00
using System.Linq;
2023-06-20 13:17:31 -05:00
using UnityEngine;
namespace SmartPoint.AssetAssistant
{
2023-07-01 21:07:29 -05:00
public class SingletonScriptableObject<T> : ScriptableObject where T : ScriptableObject
2023-06-20 13:17:31 -05:00
{
2023-07-01 21:07:29 -05:00
public static T instance;
2023-06-20 13:17:31 -05:00
2023-07-01 21:07:29 -05:00
public static T Instance
2023-06-20 13:17:31 -05:00
{
2023-07-01 21:07:29 -05:00
get
{
if (instance == null)
{
// Load the instance from resources if it's not already loaded
instance = Resources.FindObjectsOfTypeAll<T>().FirstOrDefault();
if (instance == null)
{
2023-07-14 14:42:33 -05:00
Logger.Log("An instance of " + typeof(T) +
2023-07-01 21:07:29 -05:00
" is needed in the scene, but there is none.");
}
}
return instance;
}
2023-06-20 13:17:31 -05:00
}
2023-07-01 21:07:29 -05:00
public string ClassName
2023-06-20 13:17:31 -05:00
{
2023-07-01 21:07:29 -05:00
get { return typeof(T).Name; }
2023-06-20 13:17:31 -05:00
}
2023-07-01 21:07:29 -05:00
public void OnEnable()
2023-06-20 13:17:31 -05:00
{
2023-07-01 21:07:29 -05:00
if (instance == null)
{
instance = this as T;
}
2023-06-20 13:17:31 -05:00
}
}
}