Files
ichni_Official/Assets/Scripts/UI/Base/Switch.cs

45 lines
1.1 KiB
C#
Raw Normal View History

2025-08-11 14:04:06 -04:00
using Michsky.MUIP;
namespace Ichni.UI
{
public class Switch : SettingsUIElementBase
{
public bool value;
public SwitchManager switchManager;
2026-07-25 13:27:53 -04:00
private bool _isValueChangeListenerRegistered;
2025-08-11 14:04:06 -04:00
2026-07-25 13:27:53 -04:00
public void SetUp(bool initialValue, bool preservePrefabTitle = true)
2025-08-11 14:04:06 -04:00
{
2026-07-25 13:27:53 -04:00
base.SetUp(preservePrefabTitle);
2025-08-11 14:04:06 -04:00
2026-07-25 13:27:53 -04:00
if (!_isValueChangeListenerRegistered)
2025-08-11 14:04:06 -04:00
{
2026-07-25 13:27:53 -04:00
switchManager.onValueChanged.AddListener(OnSwitchValueChanged);
_isValueChangeListenerRegistered = true;
}
2025-08-11 14:04:06 -04:00
SetValue(initialValue);
}
2026-07-25 13:27:53 -04:00
private void OnSwitchValueChanged(bool isOn)
{
value = isOn;
updateValueAction?.Invoke();
}
2025-08-11 14:04:06 -04:00
public void SetValue(bool value)
{
this.value = value;
switchManager.isOn = value;
if (switchManager.isInitialized){
switchManager.UpdateUI();
}
}
public bool GetValue()
{
return value;
}
}
2026-07-19 16:44:58 -04:00
}