Skip to content

Commit

Permalink
feat(RadialMenu): add hover events
Browse files Browse the repository at this point in the history
  • Loading branch information
omgwtfgames committed Aug 2, 2016
1 parent ebbf8e0 commit dced6ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand All @@ -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
{
Expand All @@ -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
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit dced6ae

Please sign in to comment.