40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Ichni.RhythmGame;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Ichni.Editor
|
|
{
|
|
public class DynamicUIToggle : DynamicUIElement
|
|
{
|
|
public Toggle toggle;
|
|
|
|
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
|
|
{
|
|
base.Initialize(baseElement, title, parameterName);
|
|
if (parameterName != string.Empty)
|
|
{
|
|
toggle.isOn = (bool)connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement); //获取对应变量的值
|
|
toggle.onValueChanged.AddListener(ApplyParameters);
|
|
}
|
|
else
|
|
{
|
|
toggle.isOn = false;
|
|
}
|
|
}
|
|
|
|
private void ApplyParameters(bool value)
|
|
{
|
|
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, value);
|
|
connectedBaseElement.Refresh();
|
|
}
|
|
|
|
public override DynamicUIElement AddListenerFunction(UnityAction action)
|
|
{
|
|
toggle.onValueChanged.AddListener(_ => action());
|
|
return this;
|
|
}
|
|
}
|
|
} |