4 using System.Collections.Generic;
21 [Tooltip(
"Allow single or multiple selection")]
24 [Tooltip(
"Interactives that will be managed by this controller")]
27 [Tooltip(
"Currently selected indices or default starting indices")]
28 public List<int> SelectedIndices =
new List<int>() { 0 };
30 [Tooltip(
"exposed selection changed event")]
34 private Dictionary<InteractiveToggle, UnityAction> Calls =
new Dictionary<InteractiveToggle, UnityAction>();
36 private bool mHasInit =
false;
50 for (
int i = 0; i < Interactives.Count; ++i)
54 UnityAction call = () => HandleOnSelection(itemIndex);
55 Calls.Add(Interactives[i], call);
56 Interactives[i].OnSelectEvents.AddListener(call);
59 Interactives[i].AllowDeselect =
false;
61 Interactives[i].HasSelection = SelectedIndices.Contains(i);
63 OnSelectionEvents.Invoke();
68 Interactives[itemIndex].OnSelectEvents.RemoveListener(() => HandleOnSelection(itemIndex));
69 Interactives.RemoveAt(itemIndex);
78 if (!isActiveAndEnabled ||
79 (index < 0 || Interactives.Count <= index))
84 Interactives[index].OnInputClicked(null);
91 private void HandleOnSelection(
int index)
95 for (
int i = 0; i < Interactives.Count; ++i)
99 Interactives[i].HasSelection =
false;
105 Interactives[index].HasSelection =
true;
109 SelectedIndices.Clear();
110 SelectedIndices.Add(index);
114 Interactives[index].HasSelection = !Interactives[index].HasSelection;
115 if (SelectedIndices.Contains(index))
117 SelectedIndices.Remove(index);
121 SelectedIndices.Add(index);
124 OnSelectionEvents.Invoke();
127 private void OnDestroy()
129 for (
int i = Interactives.Count - 1; i >= 0; i--)
131 RemoveInteractive(i);