Home › Page › UghToggle

UghToggle

Inherits from UghControl

An UghToggle is a button that changes state. When it changes state, its parent UghPublisher (if it is used with one) runs the command function associated with it. It can be used on its own by registering for the OnChanged and/or OnDown events.

Variables
name type description
HighlightState boolean
normalPressed UghSpritePrototype
on UghSpritePrototype
onPressed UghSpritePrototype
State boolean
Functions
name type description
OnChanged event Fires when the state of the toggle changes from true to false.
OnDown event Fires when the finger or mouse presses down on the toggle.
OnUghInputDown IEnumerator Called at the same time as OnDown.
OnUghInputUp void Called when the mouse or finger drags off this button
OnUghInputAsButton void Called when the mouse stops clicking or a finger lifts up when over this button
Inherited Variables
name type description
anchor UghSprite.Anchor The corner or custom point that the UghControl is anchored to
customAnchorOffset Vector3 The offset values for a custom anchor
flippedHorizontal boolean Is the UghSprite flipped horizonally?
flippedVertical boolean Is the UghSprite flipped vertically?
HotFingerID int The ID of the finger interacting with this control
isLegalControl boolean Is this a legal control?
normal UghSpriteDefinition The default UghSpriteDefinition for this button
Prototype UghSpritePrototype The current UghSpritePrototype for this button
Offset Vector3 The offset of the UghSprite
Inherited Functions
name type description
GetLocalCenter Vector3 Returns the local center of the UghControl
GetLocalOrigin Vector3 Returns the local origin of the UghControl
GetParentPublisher UghPublisher Returns the UghPublisher which this UghControl belongs to, or null if none
UpdateMesh void Updates this control's mesh
Inherited Class Variables
name type description
Anchor enum Enum for different common anchor positions
AnchorToTextAnchor TextAnchor Converts an Anchor enum into a TextAnchor enum
TextAnchorToAnchor UghSprite.Anchor Converts a TextAnchor enum into an Anchor enum
theOnlyLegalControls UghControl[] Array of all currently legal controls
Inherited Class Functions
name type description
ForceUpdateAllUghSpriteMeshes void Forces every UghSprite's mesh to update
GetOffsetForAnchor Vector3 Returns the Vector3 offset for a given Anchor value

_

Using UghToggle in script

UghToggle is used similarly to an UghButton and setting one up in the inspector can be seen here if you need.

Additionally to inheriting the following function from UghControl:

public override IEnumerator OnUghInputDown();
public override void OnUghInputUp();
public override void OnUghInputUpAsButton();

UghToggle also has two events which you can listen for that are fired upon a change in its state, and when it is pressed down.

public event System.Action<UghToggle,bool> OnDown;
public event Action<UghToggle> OnChanged;

If you do not use an UghPublisher to manage your UghToggle, as with many other UghControls, you must register for the OnDown and/or the OnChanged events to know when the UghToggle has been interacted with.