using UnityEngine.UI;
namespace UnityEngine.XR.Interaction.Toolkit.Samples.Hands
{
///
/// Toggles between two graphic objects based on the state of a toggle.
///
[RequireComponent(typeof(Toggle))]
public class ToggleGraphicToggler : MonoBehaviour
{
[SerializeField]
[Tooltip("Graphic object representing the toggle on position.")]
Graphic m_ToggleOnGraphic;
[SerializeField]
[Tooltip("Graphic object representing the toggle off position.")]
Graphic m_ToggleOffGraphic;
Toggle m_TargetToggle;
///
/// See .
///
void Awake()
{
m_TargetToggle = GetComponent();
}
///
/// See .
///
void OnEnable()
{
m_TargetToggle.onValueChanged.AddListener(OnToggleValueChanged);
}
///
/// See .
///
void OnDisable()
{
m_TargetToggle.onValueChanged.RemoveListener(OnToggleValueChanged);
}
void OnToggleValueChanged(bool isOn)
{
if (isOn)
m_TargetToggle.targetGraphic = m_ToggleOnGraphic;
else
m_TargetToggle.targetGraphic = m_ToggleOffGraphic;
m_ToggleOnGraphic.gameObject.SetActive(isOn);
}
}
}