NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Camp/CampTimeLineCollector.cs

77 lines
2.2 KiB
C#
Raw Normal View History

2024-01-22 13:57:19 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using PhxhSDK;
2024-01-22 15:19:21 +08:00
using Sirenix.OdinInspector;
2024-01-22 13:57:19 +08:00
using UnityEngine;
using UnityEngine.Timeline;
#if UNITY_EDITOR
using UnityEditor;
#endif
2024-01-22 15:19:21 +08:00
//[CreateAssetMenu(menuName = "营地TimeLine收集")]
2024-01-22 13:57:19 +08:00
public class CampTimeLineCollector : ScriptableObject
{
2024-01-22 15:19:21 +08:00
private const string PATH = "Assets/Art/Camp/CampTimeLineCollector.asset";
2024-01-22 13:57:19 +08:00
private static CampTimeLineCollector _instance;
public static CampTimeLineCollector Instance =>
_instance ??= AssetManager.Instance.LoadAsset<CampTimeLineCollector>(PATH);
2024-01-22 15:19:21 +08:00
[ReadOnly]
2024-01-22 13:57:19 +08:00
[SerializeField]
private List<string> _allTimelineAssetPaths = new();
private Dictionary<int, string> _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);
}
}
2024-01-22 15:19:21 +08:00
public string this[int id] => _timelineID2Path.GetValueOrDefault(id);
2024-01-22 13:57:19 +08:00
#if UNITY_EDITOR
2024-01-22 15:19:21 +08:00
[MenuItem("Tools/营地/收集所有TimeLine")]
private static void CollectAllTimeLineInMenu()
{
Instance.CollectAllTimeLine();
}
2024-01-22 13:57:19 +08:00
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
}