/// <summary> /// Adjust the image component of the parts and subscribe to the controller events. /// </summary> public void Initialize(List <SelectionWheelPart> parts, int defaultIndex) { if (!m_Binded) { Debug.Log("Controller is not binded yet! Call BindController() first!"); return; } // add an image component to each part and adjust the settings for (int i = 0; i < parts.Count; i++) { // create a gameObject for each part as a child of this one GameObject wheelPartGO = new GameObject("SelectionWheelPart " + i); wheelPartGO.transform.parent = transform; wheelPartGO.transform.localScale = Vector3.one; wheelPartGO.transform.localPosition = Vector3.zero; // add the UI part SelectionWheelPartUI wheelPartUI = wheelPartGO.AddComponent <SelectionWheelPartUI>(); wheelPartUI.Initialize(parts[i]); // set the image component Image img = wheelPartGO.GetComponent <Image>(); img.rectTransform.sizeDelta = new Vector2(Radius, Radius); img.sprite = m_Sprite; img.type = Image.Type.Filled; img.fillMethod = Image.FillMethod.Radial360; img.fillAmount = 1.0f / parts.Count - m_Offset; img.rectTransform.localEulerAngles = new Vector3(0, 0, i * 360 / parts.Count); // set the colors wheelPartUI.DefaultColor = DefaultColor; wheelPartUI.HighlightColor = HighlightColor; wheelPartUI.SelectedColor = SelectColor; wheelPartUI.DefaultOutlineColor = DefaultOutlineColor; wheelPartUI.SelectedOutlineColor = SelectedOutlineColor; // create an icon with an offset such that the icon corresponds to the right ui part of the selection wheel wheelPartUI.CreateIcon(new Vector3(-Radius / 4, -Radius / 4, 0), -img.rectTransform.localEulerAngles.z); m_Parts.Add(wheelPartUI); wheelPartUI.Unhighlight(); if (i == defaultIndex) { m_SelectedPart = wheelPartUI; wheelPartUI.Select(); } } // subcribe to the events m_ControllerEventListener.PadTouched += startRecognition; m_ControllerEventListener.PadUntouched += stopRecognition; m_ControllerEventListener.PadClicked += selectPart; }
/// <summary> /// Updates the selected part. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void selectPart(object sender, ClickedEventArgs e) { // as the event is also triggered when the selectionwheel is not active but the controller itself is we need ignore calls when recognition is off if (!m_Recognizing) { return; } int buttonID = getButtonID(); if (buttonID == -1) { return; } if (m_SelectedPart) { m_SelectedPart.Deselect(); } m_Parts[buttonID].Select(); m_SelectedPart = m_Parts[buttonID]; }
/// <summary> /// Creates a reference to the UI part. /// </summary> public virtual void Initialize(SelectionWheelPartUI uiPart) { m_UIPart = uiPart; }