//Turns and Angle and Event type into a button action protected virtual void InteractButton(float angle, ButtonEvent evt) //Can't pass ExecuteEvents as parameter? Unity gives error { if (!isActiveAndEnabled) { return; } //Get button ID from angle float buttonAngle = 360f / buttons.Count; //Each button is an arc with this angle angle = VRTK_SharedMethods.Mod((angle + -offsetRotation), 360); //Offset the touch coordinate with our offset int buttonID = (int)VRTK_SharedMethods.Mod(((angle + (buttonAngle / 2f)) / buttonAngle), buttons.Count); //Convert angle into ButtonID (This is the magic) var pointer = new PointerEventData(EventSystem.current); //Create a new EventSystem (UI) Event //If we changed buttons while moving, un-hover and un-click the last button we were on if (currentHover != buttonID && currentHover != -1) { ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerUpHandler); ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerExitHandler); buttons[currentHover].OnHoverExit.Invoke(); if (executeOnUnclick && currentPress != -1) { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerDownHandler); AttempHapticPulse(baseHapticStrength * 1.666f); } } if (evt == ButtonEvent.click) //Click button if click, and keep track of current press (executes button action) { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerDownHandler); currentPress = buttonID; if (!executeOnUnclick) { buttons[buttonID].OnClick.Invoke(); AttempHapticPulse(baseHapticStrength * 2.5f); } } else if (evt == ButtonEvent.unclick) //Clear press id to stop invoking OnHold method (hide menu) { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerUpHandler); currentPress = -1; if (executeOnUnclick) { AttempHapticPulse(baseHapticStrength * 2.5f); buttons[buttonID].OnClick.Invoke(); } } else if (evt == ButtonEvent.hoverOn && currentHover != buttonID) // Show hover UI event (darken button etc). Show menu { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerEnterHandler); buttons[buttonID].OnHoverEnter.Invoke(); AttempHapticPulse(baseHapticStrength); } currentHover = buttonID; //Set current hover ID, need this to un-hover if selected button changes }
// Token: 0x060011CC RID: 4556 RVA: 0x000671F0 File Offset: 0x000653F0 protected virtual void InteractButton(float angle, VRTK_RadialMenu.ButtonEvent evt) { float num = 360f / (float)this.buttons.Count; angle = VRTK_SharedMethods.Mod(angle + -this.offsetRotation, 360f); int num2 = (int)VRTK_SharedMethods.Mod((angle + num / 2f) / num, (float)this.buttons.Count); PointerEventData eventData = new PointerEventData(EventSystem.current); if (this.currentHover != num2 && this.currentHover != -1) { ExecuteEvents.Execute <IPointerUpHandler>(this.menuButtons[this.currentHover], eventData, ExecuteEvents.pointerUpHandler); ExecuteEvents.Execute <IPointerExitHandler>(this.menuButtons[this.currentHover], eventData, ExecuteEvents.pointerExitHandler); this.buttons[this.currentHover].OnHoverExit.Invoke(); if (this.executeOnUnclick && this.currentPress != -1) { ExecuteEvents.Execute <IPointerDownHandler>(this.menuButtons[num2], eventData, ExecuteEvents.pointerDownHandler); this.AttempHapticPulse(this.baseHapticStrength * 1.666f); } } if (evt == VRTK_RadialMenu.ButtonEvent.click) { ExecuteEvents.Execute <IPointerDownHandler>(this.menuButtons[num2], eventData, ExecuteEvents.pointerDownHandler); this.currentPress = num2; if (!this.executeOnUnclick) { this.buttons[num2].OnClick.Invoke(); this.AttempHapticPulse(this.baseHapticStrength * 2.5f); } } else if (evt == VRTK_RadialMenu.ButtonEvent.unclick) { ExecuteEvents.Execute <IPointerUpHandler>(this.menuButtons[num2], eventData, ExecuteEvents.pointerUpHandler); this.currentPress = -1; if (this.executeOnUnclick) { this.AttempHapticPulse(this.baseHapticStrength * 2.5f); this.buttons[num2].OnClick.Invoke(); } } else if (evt == VRTK_RadialMenu.ButtonEvent.hoverOn && this.currentHover != num2) { ExecuteEvents.Execute <IPointerEnterHandler>(this.menuButtons[num2], eventData, ExecuteEvents.pointerEnterHandler); this.buttons[num2].OnHoverEnter.Invoke(); this.AttempHapticPulse(this.baseHapticStrength); } this.currentHover = num2; }
//Turns and Angle and Event type into a button action protected virtual void InteractButton(TouchAngleDeflection givenTouchAngleDeflection, ButtonEvent evt) //Can't pass ExecuteEvents as parameter? Unity gives error { //Get button ID from angle float buttonAngle = 360f / buttons.Count; //Each button is an arc with this angle givenTouchAngleDeflection.angle = VRTK_SharedMethods.Mod((givenTouchAngleDeflection.angle + -offsetRotation), 360f); //Offset the touch coordinate with our offset int buttonID = (int)VRTK_SharedMethods.Mod(((givenTouchAngleDeflection.angle + (buttonAngle / 2f)) / buttonAngle), buttons.Count); //Convert angle into ButtonID (This is the magic) PointerEventData pointer = new PointerEventData(EventSystem.current); //Create a new EventSystem (UI) Event if (givenTouchAngleDeflection.deflection <= deadZone) { //No button selected. Use -1 to represent this buttonID = -1; } if (GetComponent <VRTK_IndependentRadialMenuController>().lockOption) { if (lockedOption == -1) { lockedOption = buttonID; } } else { lockedOption = -1; } if (lockedOption != -1) { buttonID = lockedOption; } optionHovered = buttonID; //If we changed buttons while moving, un-hover and un-click the last button we were on if (currentHover != buttonID && currentHover != -1) { ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerUpHandler); ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerExitHandler); buttons[currentHover].OnHoverExit.Invoke(); if (executeOnUnclick && currentPress != -1 && buttonID != -1) { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerDownHandler); AttempHapticPulse(baseHapticStrength * 1.666f); } } if (evt == ButtonEvent.click) //Click button if click, and keep track of current press (executes button action) { if (buttonID != -1) { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerDownHandler); } currentPress = buttonID; if (!executeOnUnclick && buttonID != -1) { buttons[buttonID].OnClick.Invoke(); AttempHapticPulse(baseHapticStrength * 2.5f); } } else if (evt == ButtonEvent.unclick) //Clear press id to stop invoking OnHold method (hide menu) { if (buttonID != -1) { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerUpHandler); } currentPress = -1; if (executeOnUnclick && buttonID != -1) { AttempHapticPulse(baseHapticStrength * 2.5f); buttons[buttonID].OnClick.Invoke(); } } else if (evt == ButtonEvent.hoverOn && currentHover != buttonID && buttonID != -1) // Show hover UI event (darken button etc). Show menu { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerEnterHandler); buttons[buttonID].OnHoverEnter.Invoke(); AttempHapticPulse(baseHapticStrength); } currentHover = buttonID; //Set current hover ID, need this to un-hover if selected button changes }