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

77 lines
2.2 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;
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<CampTimeLineCollector>(PATH);
[ReadOnly]
[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[(index + 1)..];
if (!int.TryParse(idStr, out var id))
{
DebugUtil.LogError($"timeline名字中找不到idpath:{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
}