You've already forked Dpr-ScriptsOnly
mirror of
https://github.com/izzy2lost/Dpr-ScriptsOnly.git
synced 2026-03-10 11:49:05 -07:00
43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace SmartPoint.AssetAssistant
|
|
{
|
|
public class SingletonScriptableObject<T> : ScriptableObject where T : ScriptableObject
|
|
{
|
|
public static T instance;
|
|
|
|
public static T Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
{
|
|
// Load the instance from resources if it's not already loaded
|
|
instance = Resources.FindObjectsOfTypeAll<T>().FirstOrDefault();
|
|
|
|
if (instance == null)
|
|
{
|
|
Logger.Log("An instance of " + typeof(T) +
|
|
" is needed in the scene, but there is none.");
|
|
}
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
public string ClassName
|
|
{
|
|
get { return typeof(T).Name; }
|
|
}
|
|
|
|
public void OnEnable()
|
|
{
|
|
if (instance == null)
|
|
{
|
|
instance = this as T;
|
|
}
|
|
}
|
|
}
|
|
} |