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; } } }