using System; using System.Collections.Generic; using System.IO; using PhxhSDK; using Sirenix.OdinInspector; using UnityEngine; using cfg.ShowCfg; #if UNITY_EDITOR using UnityEditor; #endif [CreateAssetMenu(menuName = "演出TimeLine收集")] public class CampTimeLineCollector : ScriptableObject { private const string PATH = "Assets/Art/Show/ShowTimelineCollector.asset"; private static CampTimeLineCollector instance; public static CampTimeLineCollector Instance { get { if (instance == null) { instance = AssetManager.Instance.LoadAsset(PATH); instance.Init(); } return instance; } } /// /// 所有Timeline资源路径 /// [ReadOnly] [SerializeField] private List listAllTimelineAssetPath = new(); /// /// 外层key:演出场景类型,内层key:Timeline的ID,value:资源路径 /// private readonly Dictionary> dicShowTimeline = new(); public string this[E_ShowSceneType type, int id] { get { if (!dicShowTimeline.TryGetValue(type, out var dicTimeline)) { DebugUtil.LogError("不存在的演出场景类型"); return string.Empty; } if (!dicTimeline.TryGetValue(id, out string path)) { DebugUtil.LogError("不存在的TimelineId"); return string.Empty; } return path; } } private void Init() { dicShowTimeline.Clear(); foreach (string path in listAllTimelineAssetPath) { DirectoryInfo directoryInfo = new(path); if (!Enum.TryParse(directoryInfo.Parent.Name, false, out E_ShowSceneType result)) { DebugUtil.LogError($"timeline文件夹错误,没有和{typeof(E_ShowSceneType).Name}对应"); continue; } string timeLineName = Path.GetFileNameWithoutExtension(path); int index = timeLineName.LastIndexOf("_", StringComparison.Ordinal); if (index < 0) { DebugUtil.LogError($"timeline名字中找不到_,path:{path}"); continue; } string idStr = timeLineName[(index + 1)..]; if (!int.TryParse(idStr, out int id)) { DebugUtil.LogError($"timeline名字中找不到id,path:{path}"); continue; } if (!dicShowTimeline.TryGetValue(result, out var dicTimeline)) { dicTimeline = new Dictionary(); dicShowTimeline.Add(result, dicTimeline); } dicTimeline.Add(id, path); } } #if UNITY_EDITOR [MenuItem("Tools/演出/收集所有Timeline")] private static void CollectAllTimeLineInMenu() { Instance.CollectAllTimeLine(); } public void CollectAllTimeLine() { EditorUtility.SetDirty(this); listAllTimelineAssetPath.Clear(); string[] guids = AssetDatabase.FindAssets("t:TimelineAsset", new[] { "Assets/Art/Show" }); foreach (string guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); listAllTimelineAssetPath.Add(path); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } #endif }