Feel  3.16
The best way to improve your game's feel and make it extra juicy
MoreMountains.Tools.MMTouchButton Class Reference

Add this component to a GUI Image to have it act as a button. Bind pressed down, pressed continually and released actions to it from the inspector Handles mouse and multi touch More...

Inheritance diagram for MoreMountains.Tools.MMTouchButton:
MoreMountains.Tools.MMDebugMenuSwitch

Public Types

enum  ButtonStates {
  ButtonStates.Off, ButtonStates.ButtonDown, ButtonStates.ButtonPressed, ButtonStates.ButtonUp,
  ButtonStates.Disabled
}
 

Public Member Functions

virtual void InvokeButtonStateChange (PointerEventData.FramePressState newState, PointerEventData data)
 Triggers the ButtonStateChange event for the specified state More...
 
virtual void OnPointerDown (PointerEventData data)
 Triggers the bound pointer down action More...
 
virtual void OnPointerUp (PointerEventData data)
 Triggers the bound pointer up action More...
 
virtual void OnPointerPressed ()
 Triggers the bound pointer pressed action More...
 
virtual void OnPointerEnter (PointerEventData data)
 Triggers the bound pointer enter action when touch enters zone More...
 
virtual void OnPointerExit (PointerEventData data)
 Triggers the bound pointer exit action when touch is out of zone More...
 
virtual void DisableButton ()
 Prevents the button from receiving touches More...
 
virtual void EnableButton ()
 Allows the button to receive touches More...
 
virtual void OnSubmit (BaseEventData eventData)
 On submit, raises the appropriate events More...
 

Public Attributes

bool Interactable = true
 whether or not this button can be interacted with More...
 
UnityEvent ButtonPressedFirstTime
 The method(s) to call when the button gets pressed down. More...
 
UnityEvent ButtonReleased
 The method(s) to call when the button gets released. More...
 
UnityEvent ButtonPressed
 The method(s) to call while the button is being pressed. More...
 
Sprite DisabledSprite
 the sprite to use on the button when it's in the disabled state More...
 
bool DisabledChangeColor = false
 whether or not to change color when the button is disabled More...
 
Color DisabledColor = Color.white
 the color to use when the button is disabled More...
 
Sprite PressedSprite
 the sprite to use on the button when it's in the pressed state More...
 
bool PressedChangeColor = false
 whether or not to change the button color on press More...
 
Color PressedColor = Color.white
 the color to use when the button is pressed More...
 
Sprite HighlightedSprite
 the sprite to use on the button when it's in the highlighted state More...
 
bool HighlightedChangeColor = false
 whether or not to change color when highlighting the button More...
 
Color HighlightedColor = Color.white
 the color to use when the button is highlighted More...
 
float PressedOpacity = 1f
 the new opacity to apply to the canvas group when the button is pressed More...
 
float IdleOpacity = 1f
 the new opacity to apply to the canvas group when the button is idle More...
 
float DisabledOpacity = 1f
 the new opacity to apply to the canvas group when the button is disabled More...
 
float PressedFirstTimeDelay = 0f
 the delay to apply to events when the button gets pressed for the first time More...
 
float ReleasedDelay = 0f
 the delay to apply to events when the button gets released More...
 
float BufferDuration = 0f
 the duration (in seconds) after a press during which the button can't be pressed again More...
 
Animator Animator
 an animator you can bind to this button to have its states updated to reflect the button's states More...
 
string IdleAnimationParameterName = "Idle"
 the name of the animation parameter to turn true when the button is idle More...
 
string DisabledAnimationParameterName = "Disabled"
 the name of the animation parameter to turn true when the button is disabled More...
 
string PressedAnimationParameterName = "Pressed"
 the name of the animation parameter to turn true when the button is pressed More...
 
bool MouseMode = false
 If you set this to true, you'll need to actually press the button for it to be triggered, otherwise a simple hover will trigger it (better for touch input). More...
 

Protected Member Functions

virtual void Awake ()
 On Start, we get our canvasgroup and set our initial alpha More...
 
virtual void Initialization ()
 On init we grab our Image, Animator and CanvasGroup and set them up More...
 
virtual void Update ()
 Every frame, if the touch zone is pressed, we trigger the OnPointerPressed method, to detect continuous press More...
 
virtual void LateUpdate ()
 At the end of every frame, we change our button's state if needed More...
 
virtual void InvokePressedFirstTime ()
 Raises the ButtonPressedFirstTime event More...
 
virtual void InvokeReleased ()
 Invokes the ButtonReleased event More...
 
virtual void ResetButton ()
 Resets the button's state and opacity More...
 
virtual void OnEnable ()
 OnEnable, we reset our button state More...
 
virtual void SetOpacity (float newOpacity)
 Sets the canvas group's opacity to the requested value More...
 
virtual void UpdateAnimatorStates ()
 Updates animator states based on the current state of the button More...
 

Protected Attributes

bool _zonePressed = false
 
CanvasGroup _canvasGroup
 
float _initialOpacity
 
Animator _animator
 
Image _image
 
Sprite _initialSprite
 
Color _initialColor
 
float _lastClickTimestamp = 0f
 
Selectable _selectable
 

Properties

virtual bool ReturnToInitialSpriteAutomatically [get, set]
 
virtual ButtonStates CurrentState [get, protected set]
 the current state of the button (off, down, pressed or up) More...
 

Events

System.Action< PointerEventData.FramePressState, PointerEventData > ButtonStateChange
 

Detailed Description

Add this component to a GUI Image to have it act as a button. Bind pressed down, pressed continually and released actions to it from the inspector Handles mouse and multi touch

Member Enumeration Documentation

◆ ButtonStates

The different possible states for the button : Off (default idle state), ButtonDown (button pressed for the first time), ButtonPressed (button being pressed), ButtonUp (button being released), Disabled (unclickable but still present on screen) ButtonDown and ButtonUp will only last one frame, the others will last however long you press them / disable them / do nothing

Enumerator
Off 
ButtonDown 
ButtonPressed 
ButtonUp 
Disabled 

Member Function Documentation

◆ Awake()

virtual void MoreMountains.Tools.MMTouchButton.Awake ( )
protectedvirtual

On Start, we get our canvasgroup and set our initial alpha

◆ DisableButton()

virtual void MoreMountains.Tools.MMTouchButton.DisableButton ( )
virtual

Prevents the button from receiving touches

◆ EnableButton()

virtual void MoreMountains.Tools.MMTouchButton.EnableButton ( )
virtual

Allows the button to receive touches

◆ Initialization()

virtual void MoreMountains.Tools.MMTouchButton.Initialization ( )
protectedvirtual

On init we grab our Image, Animator and CanvasGroup and set them up

Reimplemented in MoreMountains.Tools.MMDebugMenuSwitch.

◆ InvokeButtonStateChange()

virtual void MoreMountains.Tools.MMTouchButton.InvokeButtonStateChange ( PointerEventData.FramePressState  newState,
PointerEventData  data 
)
virtual

Triggers the ButtonStateChange event for the specified state

Parameters
newState
data

◆ InvokePressedFirstTime()

virtual void MoreMountains.Tools.MMTouchButton.InvokePressedFirstTime ( )
protectedvirtual

Raises the ButtonPressedFirstTime event

◆ InvokeReleased()

virtual void MoreMountains.Tools.MMTouchButton.InvokeReleased ( )
protectedvirtual

Invokes the ButtonReleased event

◆ LateUpdate()

virtual void MoreMountains.Tools.MMTouchButton.LateUpdate ( )
protectedvirtual

At the end of every frame, we change our button's state if needed

◆ OnEnable()

virtual void MoreMountains.Tools.MMTouchButton.OnEnable ( )
protectedvirtual

OnEnable, we reset our button state

◆ OnPointerDown()

virtual void MoreMountains.Tools.MMTouchButton.OnPointerDown ( PointerEventData  data)
virtual

Triggers the bound pointer down action

◆ OnPointerEnter()

virtual void MoreMountains.Tools.MMTouchButton.OnPointerEnter ( PointerEventData  data)
virtual

Triggers the bound pointer enter action when touch enters zone

◆ OnPointerExit()

virtual void MoreMountains.Tools.MMTouchButton.OnPointerExit ( PointerEventData  data)
virtual

Triggers the bound pointer exit action when touch is out of zone

◆ OnPointerPressed()

virtual void MoreMountains.Tools.MMTouchButton.OnPointerPressed ( )
virtual

Triggers the bound pointer pressed action

◆ OnPointerUp()

virtual void MoreMountains.Tools.MMTouchButton.OnPointerUp ( PointerEventData  data)
virtual

Triggers the bound pointer up action

◆ OnSubmit()

virtual void MoreMountains.Tools.MMTouchButton.OnSubmit ( BaseEventData  eventData)
virtual

On submit, raises the appropriate events

Parameters
eventData

◆ ResetButton()

virtual void MoreMountains.Tools.MMTouchButton.ResetButton ( )
protectedvirtual

Resets the button's state and opacity

◆ SetOpacity()

virtual void MoreMountains.Tools.MMTouchButton.SetOpacity ( float  newOpacity)
protectedvirtual

Sets the canvas group's opacity to the requested value

Parameters
newOpacity

◆ Update()

virtual void MoreMountains.Tools.MMTouchButton.Update ( )
protectedvirtual

Every frame, if the touch zone is pressed, we trigger the OnPointerPressed method, to detect continuous press

◆ UpdateAnimatorStates()

virtual void MoreMountains.Tools.MMTouchButton.UpdateAnimatorStates ( )
protectedvirtual

Updates animator states based on the current state of the button

Member Data Documentation

◆ _animator

Animator MoreMountains.Tools.MMTouchButton._animator
protected

◆ _canvasGroup

CanvasGroup MoreMountains.Tools.MMTouchButton._canvasGroup
protected

◆ _image

Image MoreMountains.Tools.MMTouchButton._image
protected

◆ _initialColor

Color MoreMountains.Tools.MMTouchButton._initialColor
protected

◆ _initialOpacity

float MoreMountains.Tools.MMTouchButton._initialOpacity
protected

◆ _initialSprite

Sprite MoreMountains.Tools.MMTouchButton._initialSprite
protected

◆ _lastClickTimestamp

float MoreMountains.Tools.MMTouchButton._lastClickTimestamp = 0f
protected

◆ _selectable

Selectable MoreMountains.Tools.MMTouchButton._selectable
protected

◆ _zonePressed

bool MoreMountains.Tools.MMTouchButton._zonePressed = false
protected

◆ Animator

Animator MoreMountains.Tools.MMTouchButton.Animator

an animator you can bind to this button to have its states updated to reflect the button's states

◆ BufferDuration

float MoreMountains.Tools.MMTouchButton.BufferDuration = 0f

the duration (in seconds) after a press during which the button can't be pressed again

◆ ButtonPressed

UnityEvent MoreMountains.Tools.MMTouchButton.ButtonPressed

The method(s) to call while the button is being pressed.

◆ ButtonPressedFirstTime

UnityEvent MoreMountains.Tools.MMTouchButton.ButtonPressedFirstTime

The method(s) to call when the button gets pressed down.

◆ ButtonReleased

UnityEvent MoreMountains.Tools.MMTouchButton.ButtonReleased

The method(s) to call when the button gets released.

◆ DisabledAnimationParameterName

string MoreMountains.Tools.MMTouchButton.DisabledAnimationParameterName = "Disabled"

the name of the animation parameter to turn true when the button is disabled

◆ DisabledChangeColor

bool MoreMountains.Tools.MMTouchButton.DisabledChangeColor = false

whether or not to change color when the button is disabled

◆ DisabledColor

Color MoreMountains.Tools.MMTouchButton.DisabledColor = Color.white

the color to use when the button is disabled

◆ DisabledOpacity

float MoreMountains.Tools.MMTouchButton.DisabledOpacity = 1f

the new opacity to apply to the canvas group when the button is disabled

◆ DisabledSprite

Sprite MoreMountains.Tools.MMTouchButton.DisabledSprite

the sprite to use on the button when it's in the disabled state

◆ HighlightedChangeColor

bool MoreMountains.Tools.MMTouchButton.HighlightedChangeColor = false

whether or not to change color when highlighting the button

◆ HighlightedColor

Color MoreMountains.Tools.MMTouchButton.HighlightedColor = Color.white

the color to use when the button is highlighted

◆ HighlightedSprite

Sprite MoreMountains.Tools.MMTouchButton.HighlightedSprite

the sprite to use on the button when it's in the highlighted state

◆ IdleAnimationParameterName

string MoreMountains.Tools.MMTouchButton.IdleAnimationParameterName = "Idle"

the name of the animation parameter to turn true when the button is idle

◆ IdleOpacity

float MoreMountains.Tools.MMTouchButton.IdleOpacity = 1f

the new opacity to apply to the canvas group when the button is idle

◆ Interactable

bool MoreMountains.Tools.MMTouchButton.Interactable = true

whether or not this button can be interacted with

◆ MouseMode

bool MoreMountains.Tools.MMTouchButton.MouseMode = false

If you set this to true, you'll need to actually press the button for it to be triggered, otherwise a simple hover will trigger it (better for touch input).

◆ PressedAnimationParameterName

string MoreMountains.Tools.MMTouchButton.PressedAnimationParameterName = "Pressed"

the name of the animation parameter to turn true when the button is pressed

◆ PressedChangeColor

bool MoreMountains.Tools.MMTouchButton.PressedChangeColor = false

whether or not to change the button color on press

◆ PressedColor

Color MoreMountains.Tools.MMTouchButton.PressedColor = Color.white

the color to use when the button is pressed

◆ PressedFirstTimeDelay

float MoreMountains.Tools.MMTouchButton.PressedFirstTimeDelay = 0f

the delay to apply to events when the button gets pressed for the first time

◆ PressedOpacity

float MoreMountains.Tools.MMTouchButton.PressedOpacity = 1f

the new opacity to apply to the canvas group when the button is pressed

◆ PressedSprite

Sprite MoreMountains.Tools.MMTouchButton.PressedSprite

the sprite to use on the button when it's in the pressed state

◆ ReleasedDelay

float MoreMountains.Tools.MMTouchButton.ReleasedDelay = 0f

the delay to apply to events when the button gets released

Property Documentation

◆ CurrentState

virtual ButtonStates MoreMountains.Tools.MMTouchButton.CurrentState
getprotected set

the current state of the button (off, down, pressed or up)

◆ ReturnToInitialSpriteAutomatically

virtual bool MoreMountains.Tools.MMTouchButton.ReturnToInitialSpriteAutomatically
getset

Event Documentation

◆ ButtonStateChange

System.Action<PointerEventData.FramePressState, PointerEventData> MoreMountains.Tools.MMTouchButton.ButtonStateChange

The documentation for this class was generated from the following file: