Inspector内容开始填充完善
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ichni.RhythmGame;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIEnumDropdown : DynamicUIElement
|
||||
{
|
||||
public TMP_Dropdown dropdown;
|
||||
|
||||
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
|
||||
{
|
||||
base.Initialize(baseElement, title, parameterName);
|
||||
dropdown.value = (int)connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement); //获取对应变量的值
|
||||
dropdown.onValueChanged.AddListener(ApplyParameters);
|
||||
}
|
||||
|
||||
public void SetUpEnum(Type enumType)
|
||||
{
|
||||
dropdown.ClearOptions();
|
||||
List<string> enumNameList = System.Enum.GetNames(enumType).ToList();
|
||||
dropdown.AddOptions(enumNameList);
|
||||
}
|
||||
|
||||
private void ApplyParameters(int value)
|
||||
{
|
||||
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, value);
|
||||
connectedBaseElement.Refresh();
|
||||
}
|
||||
|
||||
public void AddListenerFunction(UnityAction<int> action)
|
||||
{
|
||||
dropdown.onValueChanged.AddListener(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user