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

40 lines
1.2 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)ReflectionHelper.GetDeepValue(connectedBaseElement, parameterName);
toggle.onValueChanged.AddListener(ApplyParameters);
}
else
{
toggle.isOn = false;
}
}
private void ApplyParameters(bool value)
{
ReflectionHelper.SetDeepValue(connectedBaseElement, parameterName, value);
connectedBaseElement.Refresh();
}
public override DynamicUIElement AddListenerFunction(UnityAction action)
{
toggle.onValueChanged.AddListener(_ => action());
return this;
}
}
}