using UnityEngine;
using UnityEngine.UI;
namespace Convai.Scripts.Runtime.UI
{
///
/// Base class to handle different toggle status, including loading and saving
///
public class ActiveStatusHandler : MonoBehaviour
{
[SerializeField] protected Toggle _activeStatusToggle;
private void Awake()
{
// Subscribe to the toggle's value change event.
_activeStatusToggle.onValueChanged.AddListener(OnStatusChange);
}
///
/// Subscribe to events when this component is enabled.
///
private void OnEnable()
{
// Subscribe to the event when saved data is loaded.
UISaveLoadSystem.Instance.OnLoad += UISaveLoadSystem_OnLoad;
// Subscribe to the event when data is saved.
UISaveLoadSystem.Instance.OnSave += UISaveLoadSystem_OnSave;
}
///
/// Unsubscribe from events when this component is disabled.
///
private void OnDisable()
{
// Subscribe to the event when saved data is loaded.
UISaveLoadSystem.Instance.OnLoad -= UISaveLoadSystem_OnLoad;
// Subscribe to the event when data is saved.
UISaveLoadSystem.Instance.OnSave -= UISaveLoadSystem_OnSave;
}
///
/// Event handler for when saved data is loaded.
///
protected virtual void UISaveLoadSystem_OnLoad()
{
}
///
/// Event handler for when data is saved.
///
protected virtual void UISaveLoadSystem_OnSave()
{
}
///
/// Set the activation status
///
/// The new activation status.
public virtual void OnStatusChange(bool value)
{
}
}
}