56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
#if UNITY_EDITOR
|
|
using System.Linq;
|
|
using Sirenix.OdinInspector.Editor;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace SLSUtilities.WwiseAssistance.Editor
|
|
{
|
|
public class WwiseEventDrawer : OdinAttributeDrawer<WwiseEventAttribute, uint>
|
|
{
|
|
protected override void DrawPropertyLayout(GUIContent label)
|
|
{
|
|
uint currentID = this.ValueEntry.SmartValue;
|
|
|
|
// 获取显示名
|
|
string displayName = WwiseDataCache.GetName(currentID);
|
|
if (currentID == 0) displayName = "None (Click to Search)";
|
|
|
|
Rect rect = EditorGUILayout.GetControlRect(label != null);
|
|
if (label != null)
|
|
{
|
|
rect = EditorGUI.PrefixLabel(rect, label);
|
|
}
|
|
|
|
// 绘制触发按钮
|
|
if (GUI.Button(rect, displayName, EditorStyles.popup))
|
|
{
|
|
ShowSelector(rect);
|
|
}
|
|
}
|
|
|
|
private void ShowSelector(Rect rect)
|
|
{
|
|
var allNames = WwiseDataCache.GetAllNames();
|
|
WwiseEventSelector selector = new WwiseEventSelector(allNames);
|
|
|
|
// 设置窗口大小
|
|
// 宽度:自适应,最小 250
|
|
float width = Mathf.Max(rect.width, 250);
|
|
|
|
// 高度:限制为 300
|
|
// 这既能保证空状态下不显得太长,也能在列表展开时显示足够多的条目(约10-12条)
|
|
selector.ShowInPopup(rect, new Vector2(width, 300));
|
|
|
|
selector.SelectionConfirmed += (selectedData) =>
|
|
{
|
|
var selectedName = selectedData.FirstOrDefault();
|
|
uint newID = WwiseDataCache.GetID(selectedName);
|
|
|
|
this.ValueEntry.SmartValue = newID;
|
|
this.ValueEntry.ApplyChanges();
|
|
};
|
|
}
|
|
}
|
|
}
|
|
#endif |