架构大更
This commit is contained in:
42
docs/References/BaseCollection.cs
Normal file
42
docs/References/BaseCollection.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user