/// <summary> /// On start create all the instances if the referenced object is a prefab /// </summary> protected void Start() { for (int i = 0; i < ButtonStates.Length; i++) { if (ButtonStates[i].Prefab != null) { if (StaticExtensions.IsPrefab(ButtonStates[i].Prefab)) { ButtonStates[i].Instance = Instantiate(ButtonStates[i].Prefab, this.transform.position, this.transform.rotation) as GameObject; ButtonStates[i].Instance.transform.parent = this.transform; // Remove Clone Name ButtonStates[i].Instance.name = ButtonStates[i].Instance.name.Substring(0, ButtonStates[i].Instance.name.Length - 7); } else { ButtonStates[i].Instance = ButtonStates[i].Prefab; } ButtonStates[i].Instance.transform.localScale = Vector3.Scale(ButtonStates[i].Instance.transform.localScale, ButtonStates[i].Scale); ButtonStates[i].Instance.transform.localPosition = ButtonStates[i].Instance.transform.localPosition + ButtonStates[i].Offset; // Now set inactive till state change ButtonStates[i].Instance.SetActive(false); } OnStateChange(ButtonStateEnum.Observation); } }
/// <summary> /// Init widgets goes through and validates if a widget /// needs to be spawned or already exists. /// </summary> public void InitWidgets() { foreach (CursorWidgetData data in CursorWidgets) { // Only instantiate widgets that don't exist yet, in case more have been added if (data.CursorWidgetPrefab != null && data.CursorWidgetObject == null) { if (StaticExtensions.IsPrefab(data.CursorWidgetPrefab.gameObject)) { data.CursorWidgetObject = Instantiate(data.CursorWidgetPrefab); } else { data.CursorWidgetObject = data.CursorWidgetPrefab; } data.CursorWidgetObject.CursorObj = this.gameObject; data.CursorWidgetObject.SwitchAnchorType(data.CursorWidgetObject.AnchorType); data.CursorWidgetObject.gameObject.SetActive(false); } } }