5 using System.Collections.Generic;
10 [RequireComponent(typeof(InteractiveSet))]
13 [Tooltip(
"Gameobject containing GridLayoutGroup")]
16 [Tooltip(
"Prefab for your interactive.")]
19 [Tooltip(
"scale for new instance of InteractivePrefab")]
20 public Vector3 PrefabScale =
new Vector3(2000, 2000, 2000);
22 [Tooltip(
"Data to fill the InteractiveSet.")]
23 public List<string> Titles =
new List<string>();
28 Grid = Grid == null ? transform.Find(
"Canvas/Grid").gameObject : Grid;
31 if (interactive == null)
33 Debug.LogError(
"No interactive attached to Prefab, " +
34 "please attach one of the Interactive scripts " +
35 "to your InteractiveGroup Prefab!");
43 private List<InteractiveToggle> Interactives {
46 return GetInteractiveSet().Interactives;
50 GetInteractiveSet().Interactives = value;
56 return GetComponent<InteractiveSet>();
62 private void CreateInteractives()
64 for (
int i = Interactives.Count; i < Titles.Count; i++)
66 GameObject PrefabInst = Instantiate(InteractivePrefab, Grid.transform) as GameObject;
67 PrefabInst.transform.localScale = PrefabScale;
69 if (InterInst == null)
71 Debug.LogWarning(
"Please add an InteractiveToggle for your prefab " +
72 gameObject.name +
" to use it in an InteractiveGroup.");
76 Interactives.Add(InterInst);
86 RemoveInteractives(Titles.Count);
89 for (
int i = 0; i < Interactives.Count; i++)
92 string title = Titles[i];
97 GetInteractiveSet().SelectedIndices.Clear();
98 GetInteractiveSet().UpdateInteractives();
101 private void OnDestroy()
103 RemoveInteractives();
111 private void RemoveInteractives(
int keep = 0)
113 for (
int i = Interactives.Count - 1; i >= keep; i--)
116 GetInteractiveSet().RemoveInteractive(i);
117 DestroyImmediate(interactive.gameObject);