diff --git a/Assets/SteamVR_Unity_Toolkit/Scripts/Controls/2D/RadialMenu/RadialMenu.cs b/Assets/SteamVR_Unity_Toolkit/Scripts/Controls/2D/RadialMenu/RadialMenu.cs index ad86b600e..fdd82e9f0 100644 --- a/Assets/SteamVR_Unity_Toolkit/Scripts/Controls/2D/RadialMenu/RadialMenu.cs +++ b/Assets/SteamVR_Unity_Toolkit/Scripts/Controls/2D/RadialMenu/RadialMenu.cs @@ -48,7 +48,7 @@ private void Update() //Keep track of pressed button and constantly invoke Hold event if (currentPress != -1) { - buttons[currentPress].Press(); + buttons[currentPress].OnHold.Invoke(); } } @@ -71,12 +71,13 @@ private void InteractButton(float angle, ButtonEvent evt) //Can't pass ExecuteEv { ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerUpHandler); ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerExitHandler); + buttons[currentHover].OnHoverExit.Invoke(); } if (evt == ButtonEvent.click) //Click button if click, and keep track of current press { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerDownHandler); currentPress = buttonID; - buttons[buttonID].Click(); + buttons[buttonID].OnClick.Invoke(); } else if (evt == ButtonEvent.unclick) //Clear press id to stop invoking OnHold method { @@ -86,6 +87,7 @@ private void InteractButton(float angle, ButtonEvent evt) //Can't pass ExecuteEv else if (evt == ButtonEvent.hoverOn && currentHover != buttonID) // Show hover UI event (darken button etc) { ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerEnterHandler); + buttons[buttonID].OnHoverEnter.Invoke(); } currentHover = buttonID; //Set current hover ID, need this to un-hover if selected button changes } @@ -127,6 +129,7 @@ public void StopTouching() { var pointer = new PointerEventData(EventSystem.current); ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerExitHandler); + buttons[currentHover].OnHoverExit.Invoke(); currentHover = -1; } } @@ -295,18 +298,11 @@ private float mod(float a, float b) public class RadialMenuButton { public Sprite ButtonIcon; + public UnityEvent OnClick; public UnityEvent OnHold; - - public void Press() - { - OnHold.Invoke(); - } - - public void Click() - { - OnClick.Invoke(); - } + public UnityEvent OnHoverEnter; + public UnityEvent OnHoverExit; } public enum ButtonEvent diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 1a9cbdb28..4f4c9962b 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -124,6 +124,8 @@ There are a number of parameters that can be set on the Prefab which are provide * **ButtonIcon:** Icon to use inside the button arc (should be circular). * **OnClick():** Methods to invoke when the button is clicked. * **OnHold():** Methods to invoke each frame while the button is held down. + * **OnHoverEnter():** Methods to invoke when button is first hovered over. + * **OnHoverExit():** Methods to invoke when button leaves the hovered state. * **Button Prefab:** The base for each button in the menu, by default set to a dynamic circle arc that will fill up a portion of the menu. * **Button Thickness:** Percentage of the menu the buttons should fill, 1.0 is a pie slice, 0.1 is a thin ring. * **Button Color:** The background color of the buttons, default is white.