using System; using System.Collections; using System.Collections.Generic; using System.IO; using PhxhSDK; using Sirenix.OdinInspector; using UnityEngine; using UnityEngine.Timeline; #if UNITY_EDITOR using UnityEditor; #endif //[CreateAssetMenu(menuName = "营地TimeLine收集")] public class CampTimeLineCollector : ScriptableObject { private const string PATH = "Assets/Art/Camp/CampTimeLineCollector.asset"; private static CampTimeLineCollector _instance; public static CampTimeLineCollector Instance => _instance ??= AssetManager.Instance.LoadAsset(PATH); [ReadOnly] [SerializeField] private List _allTimelineAssetPaths = new(); private Dictionary _timelineID2Path = new(); private void Awake() { _timelineID2Path.Clear(); foreach (var path in _allTimelineAssetPaths) { var timeLineName = Path.GetFileNameWithoutExtension(path); var index = timeLineName.LastIndexOf("_", StringComparison.Ordinal); if (index < 0) { DebugUtil.LogError($"timeline名字中找不到_,path:{path}"); continue; } var idStr = timeLineName.Substring(index + 1); if (!int.TryParse(idStr, out var id)) { DebugUtil.LogError($"timeline名字中找不到id,path:{path}"); continue; } _timelineID2Path.Add(id, path); } } public string this[int id] => _timelineID2Path.GetValueOrDefault(id); #if UNITY_EDITOR [MenuItem("Tools/营地/收集所有TimeLine")] private static void CollectAllTimeLineInMenu() { Instance.CollectAllTimeLine(); } public void CollectAllTimeLine() { EditorUtility.SetDirty(this); _allTimelineAssetPaths.Clear(); var guids = AssetDatabase.FindAssets("t:TimelineAsset", new[] { "Assets/Art/Camp/Timeline" }); foreach (var guid in guids) { var path = AssetDatabase.GUIDToAssetPath(guid); _allTimelineAssetPaths.Add(path); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } #endif }