75 lines
2.4 KiB
C#
75 lines
2.4 KiB
C#
#if UNITY_EDITOR
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace SLSUtilities.WwiseAssistance.Editor
|
|
{
|
|
// 用于管理 Wwise 数据缓存的静态类
|
|
public static class WwiseDataCache
|
|
{
|
|
private static Dictionary<string, uint> _nameToId = new Dictionary<string, uint>();
|
|
private static Dictionary<uint, string> _idToName = new Dictionary<uint, string>();
|
|
private static bool _isDirty = true; // 标记数据是否需要刷新
|
|
|
|
// 当脚本重新编译时,标记为 dirty
|
|
[UnityEditor.Callbacks.DidReloadScripts]
|
|
private static void OnScriptsReloaded() => _isDirty = true;
|
|
|
|
public static void RefreshData()
|
|
{
|
|
if (!_isDirty && _nameToId.Count > 0) return;
|
|
|
|
_nameToId.Clear();
|
|
_idToName.Clear();
|
|
|
|
Type eventsType = Type.GetType("AK+EVENTS, Assembly-CSharp");
|
|
|
|
if (eventsType == null)
|
|
{
|
|
eventsType = AppDomain.CurrentDomain.GetAssemblies()
|
|
.SelectMany(a => a.GetTypes())
|
|
.FirstOrDefault(t => t.FullName == "AK.EVENTS" || (t.Name == "EVENTS" && t.DeclaringType?.Name == "AK"));
|
|
}
|
|
|
|
if (eventsType != null)
|
|
{
|
|
FieldInfo[] fields = eventsType.GetFields(BindingFlags.Public | BindingFlags.Static);
|
|
foreach (var field in fields)
|
|
{
|
|
if (field.FieldType == typeof(uint))
|
|
{
|
|
string name = field.Name;
|
|
uint id = (uint)field.GetValue(null);
|
|
|
|
if (!_nameToId.ContainsKey(name)) _nameToId.Add(name, id);
|
|
if (!_idToName.ContainsKey(id)) _idToName.Add(id, name);
|
|
}
|
|
}
|
|
}
|
|
_isDirty = false;
|
|
}
|
|
|
|
public static string GetName(uint id)
|
|
{
|
|
RefreshData();
|
|
return _idToName.TryGetValue(id, out string name) ? name : "Invalid ID";
|
|
}
|
|
|
|
public static uint GetID(string name)
|
|
{
|
|
RefreshData();
|
|
return _nameToId.TryGetValue(name, out uint id) ? id : 0;
|
|
}
|
|
|
|
public static IEnumerable<string> GetAllNames()
|
|
{
|
|
RefreshData();
|
|
return _nameToId.Keys;
|
|
}
|
|
}
|
|
}
|
|
#endif |