42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using Sirenix.OdinInspector;
|
|
using SLSUtilities.General;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.Core
|
|
{
|
|
public partial class BaseCollection<T> : SerializedScriptableObject where T : BaseCollection<T>
|
|
{
|
|
private static T _instance;
|
|
|
|
public static T Instance
|
|
{
|
|
get
|
|
{
|
|
string type = typeof(T).Name;
|
|
if (_instance == null)
|
|
{
|
|
string path = $"BaseCollections/{type}";
|
|
_instance = Resources.Load<T>(path);
|
|
}
|
|
#if UNITY_EDITOR
|
|
if (_instance == null)
|
|
{
|
|
string[] guids = UnityEditor.AssetDatabase.FindAssets($"t:{type}");
|
|
if (guids.Length > 0)
|
|
{
|
|
string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guids[0]);
|
|
_instance = UnityEditor.AssetDatabase.LoadAssetAtPath<T>(path);
|
|
}
|
|
}
|
|
#endif
|
|
if (_instance == null)
|
|
{
|
|
Debug.LogError($"项目中没有找到类型为 {typeof(T).Name} 的 BaseCollection。" +
|
|
$"请确保已创建该 ScriptableObject 并将其放置在 Resources 文件夹中。");
|
|
}
|
|
|
|
return _instance;
|
|
}
|
|
}
|
|
}
|
|
} |