Files
Cielonos/Assets/Scripts/Core/BaseCollection.cs

42 lines
1.4 KiB
C#
Raw Normal View History

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