Files
ichni_Creator_Studio/Assets/Scripts/DynamicUI/DynamicUIElements/Simple/DynamicUIEnumDropdown.cs
TRAfoer a31269c632 fastTracker
Signed-off-by: TRAfoer <lhf190@outlook.com>
2026-01-07 23:48:28 +08:00

45 lines
1.5 KiB
C#

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 List<int> realValues;
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
{
base.Initialize(baseElement, title, parameterName);
object value = ReflectionHelper.GetDeepValue(connectedBaseElement, parameterName);
dropdown.value = value != null ? (int)value : 0;
dropdown.onValueChanged.AddListener(ApplyParameters);
}
public void SetUpEnum(Type enumType)
{
dropdown.ClearOptions();
List<string> enumNameList = System.Enum.GetNames(enumType).ToList();
realValues = System.Enum.GetValues(enumType).Cast<int>().ToList();
dropdown.AddOptions(enumNameList);
}
private void ApplyParameters(int value)
{
ReflectionHelper.SetDeepValue(connectedBaseElement, parameterName, realValues[value]);
connectedBaseElement.Refresh();
}
public override DynamicUIElement AddListenerFunction(UnityAction action)
{
dropdown.onValueChanged.AddListener(_ => action());
return this;
}
}
}