36 lines
791 B
C#
36 lines
791 B
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Script.UI
|
|
{
|
|
public class AnsweringToggleHelper : MonoBehaviour
|
|
{
|
|
public int index;
|
|
private Toggle _toggle;
|
|
private Action<int> action;
|
|
public Toggle toggle => _toggle;
|
|
|
|
private void Awake()
|
|
{
|
|
_toggle = GetComponent<Toggle>();
|
|
_toggle.onValueChanged.AddListener(OnValueChanged);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_toggle.onValueChanged.RemoveListener(OnValueChanged);
|
|
}
|
|
|
|
private void OnValueChanged(bool arg0)
|
|
{
|
|
if (arg0)
|
|
action?.Invoke(index);
|
|
}
|
|
|
|
public void SetAction(Action<int> ac)
|
|
{
|
|
this.action = ac;
|
|
}
|
|
}
|
|
} |