NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Show/ShowTimelineCollector.cs

125 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<CampTimeLineCollector>(PATH);
instance.Init();
}
return instance;
}
}
/// <summary>
/// 所有Timeline资源路径
/// </summary>
[ReadOnly]
[SerializeField]
private List<string> listAllTimelineAssetPath = new();
/// <summary>
/// 外层key演出场景类型内层keyTimeline的IDvalue:资源路径
/// </summary>
private readonly Dictionary<E_ShowSceneType, Dictionary<int, string>> 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名字中找不到idpath:{path}");
continue;
}
if (!dicShowTimeline.TryGetValue(result, out var dicTimeline))
{
dicTimeline = new Dictionary<int, string>();
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
}