添加插件
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Obvious.Soap
|
||||
{
|
||||
[HelpURL("https://obvious-game.gitbook.io/soap/soap-core-assets/scriptable-singleton")]
|
||||
public abstract class ScriptableSingleton<T> : ScriptableBase where T : ScriptableObject
|
||||
{
|
||||
private static T _instance;
|
||||
|
||||
public static T Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance)
|
||||
return _instance;
|
||||
|
||||
var assetName = typeof(T).Name;
|
||||
_instance = Resources.Load<T>(assetName);
|
||||
|
||||
if (_instance)
|
||||
return _instance;
|
||||
|
||||
var all = Resources.LoadAll<T>(string.Empty);
|
||||
if (all != null && all.Length > 0)
|
||||
{
|
||||
_instance = all[0];
|
||||
return _instance;
|
||||
}
|
||||
|
||||
Debug.LogError("[Soap] No instance of Singleton:" + assetName + " found in Resources folder.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Need for editor if direct access from classes (without passing through Instance property)
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
if (_instance == null)
|
||||
_instance = this as T;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4993914fb8e01ee4abefb5c9c02f4dee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user