Files
Cielonos/Assets/Scripts/Settings/UI/SettingsEntryToggle.cs
SoulliesOfficial 6d7ebc5825 Passion & UI
2026-06-12 17:11:39 -04:00

37 lines
883 B
C#

using UnityEngine;
using UnityEngine.UI;
namespace Cielonos.Settings.UI
{
/// <summary>
/// bool 字段的设置条目 — 使用 Toggle 组件。
/// </summary>
public class SettingsEntryToggle : SettingsEntryBase
{
[SerializeField] private Toggle toggle;
protected override void SetupUI()
{
if (toggle != null)
toggle.onValueChanged.AddListener(OnToggleChanged);
}
public override void RefreshValue()
{
if (toggle != null)
toggle.SetIsOnWithoutNotify((bool)GetFieldValue());
}
private void OnToggleChanged(bool value)
{
SetFieldValue(value);
}
private void OnDestroy()
{
if (toggle != null)
toggle.onValueChanged.RemoveListener(OnToggleChanged);
}
}
}