// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #if GT_USE_UGUI using System; using UnityEngine; using UnityEngine.UI; namespace Microsoft.MixedReality.GraphicsTools.Samples.MeshInstancing { /// /// Logic to toggle on/off samples based on UI toggle. /// public class SamplesToggle : MonoBehaviour { /// /// UnityUI toggle/sample pair. /// [Serializable] public struct ToggleSample { public Toggle Toggle; public GameObject Sample; } /// /// The list of samples to toggle with their UI toggle. /// public ToggleSample[] toggleSamples = null; /// /// Subscribe to toggle events. /// private void OnEnable() { foreach (var pair in toggleSamples) { if (pair.Toggle != null) { pair.Toggle.onValueChanged.AddListener((bool on) => { if (pair.Sample != null) { pair.Sample.SetActive(on); } }); } } } } } #endif // GT_USE_UGUI