2025-02-13 02:04:41 -05:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Ichni.RhythmGame;
|
|
|
|
|
using UnityEngine;
|
2025-02-16 11:15:42 -05:00
|
|
|
using UnityEngine.Events;
|
2025-02-13 02:04:41 -05:00
|
|
|
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);
|
2025-02-21 14:08:32 -05:00
|
|
|
if (parameterName != string.Empty)
|
|
|
|
|
{
|
|
|
|
|
toggle.isOn = (bool)connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement); //获取对应变量的值
|
|
|
|
|
toggle.onValueChanged.AddListener(ApplyParameters);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
toggle.isOn = false;
|
|
|
|
|
}
|
2025-02-13 02:04:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ApplyParameters(bool value)
|
|
|
|
|
{
|
|
|
|
|
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, value);
|
|
|
|
|
connectedBaseElement.Refresh();
|
|
|
|
|
}
|
2025-02-16 11:15:42 -05:00
|
|
|
|
2025-03-20 02:42:10 -04:00
|
|
|
public override void AddListenerFunction(UnityAction action)
|
2025-02-16 11:15:42 -05:00
|
|
|
{
|
2025-03-20 02:42:10 -04:00
|
|
|
toggle.onValueChanged.AddListener(_ => action());
|
2025-02-16 11:15:42 -05:00
|
|
|
}
|
2025-02-13 02:04:41 -05:00
|
|
|
}
|
|
|
|
|
}
|