using System; using AlicizaX.Runtime; using UnityEngine; namespace AlicizaX.Editor { public static class ScriptableSingletonUtil { public static T Get() where T : ScriptableObject { string assetType = typeof(T).Name; T globalSetting = default; string[] globalAssetPaths = UnityEditor.AssetDatabase.FindAssets($"t:{assetType}"); if (globalAssetPaths.Length > 1) { foreach (var assetPath in globalAssetPaths) { Debug.LogError($"Could not had Multiple {assetType}. Repeated Path: {UnityEditor.AssetDatabase.GUIDToAssetPath(assetPath)}"); } throw new Exception($"Could not had Multiple {assetType}"); } if (globalAssetPaths.Length == 1) { string path = UnityEditor.AssetDatabase.GUIDToAssetPath(globalAssetPaths[0]); globalSetting = UnityEditor.AssetDatabase.LoadAssetAtPath(path); } if (globalSetting == null) { Debug.LogError($"Could not found {assetType} asset"); return null; } return globalSetting; } } }