Component.GetComponentIndex()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, InstantiateParameters)
Object.InstantiateAsync<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Namespace: UnityEngine.UI Assembly: UnityEngine.UI.dll Syntax[AddComponentMenu("UI/Selectable", 35)]
[ExecuteAlways]
[SelectionBase]
[DisallowMultipleComponent]
public class Selectable : UIBehaviour, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IEventSystemHandler
Constructors Selectable() Declaration Fields m_CurrentIndex Declaration
protected int m_CurrentIndex
Field Value s_SelectableCount Declaration
protected static int s_SelectableCount
Field Value s_Selectables Declaration
protected static Selectable[] s_Selectables
Field Value Properties allSelectableCount
How many selectable elements are currently active.
Declarationpublic static int allSelectableCount { get; }
Property Value allSelectables
A List instance of the allSelectablesArray to maintain API compatibility.
Declaration[Obsolete("Replaced with allSelectablesArray to have better performance when disabling a element", false)]
public static List<Selectable> allSelectables { get; }
Property Value allSelectablesArray
Copy of the array of all the selectable objects currently active in the scene.
Declarationpublic static Selectable[] allSelectablesArray { get; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class Example : MonoBehaviour
{
//Displays the names of all selectable elements in the scene
public void GetNames()
{
foreach (Selectable selectableUI in Selectable.allSelectablesArray)
{
Debug.Log(selectableUI.name);
}
}
}
animationTriggers
The AnimationTriggers for this selectable object.
Declarationpublic AnimationTriggers animationTriggers { get; set; }
Property Value animator
Convenience function to get the Animator component on the GameObject.
Declarationpublic Animator animator { get; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
private Animator buttonAnimator;
public Button button;
void Start()
{
//Assigns the "buttonAnimator" with the button's animator.
buttonAnimator = button.animator;
}
}
colors
The ColorBlock for this selectable object.
Declarationpublic ColorBlock colors { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Button button;
void Start()
{
//Resets the colors in the buttons transitions.
button.colors = ColorBlock.defaultColorBlock;
}
}
currentSelectionState Declaration
protected Selectable.SelectionState currentSelectionState { get; }
Property Value image
Convenience function that converts the referenced Graphic to a Image, if possible.
Declarationpublic Image image { get; set; }
Property Value interactable
Is this object interactable.
Declarationpublic bool interactable { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class Example : MonoBehaviour
{
public Button startButton;
public bool playersReady;
void Update()
{
// checks if the players are ready and if the start button is useable
if (playersReady == true && startButton.interactable == false)
{
//allows the start button to be used
startButton.interactable = true;
}
}
}
navigation
The Navigation setting for this selectable object.
Declarationpublic Navigation navigation { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Button button;
void Start()
{
//Set the navigation to the default value. ("Automatic" is the default value).
button.navigation = Navigation.defaultNavigation;
}
}
spriteState
The SpriteState for this selectable object.
Declarationpublic SpriteState spriteState { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
//Creates an instance of a sprite state (This includes the highlighted, pressed and disabled sprite.
public SpriteState sprState = new SpriteState();
public Button btnMain;
void Start()
{
//Assigns the new sprite states to the button.
btnMain.spriteState = sprState;
}
}
targetGraphic
Graphic that will be transitioned upon.
Declarationpublic Graphic targetGraphic { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Image newImage;
public Button btnMain;
void SomeFunction()
{
//Displays the sprite transitions on the image when the transition to Highlighted,pressed or disabled is made.
btnMain.targetGraphic = newImage;
}
}
transition
The type of transition that will be applied to the targetGraphic when the state changes.
Declarationpublic Selectable.Transition transition { get; set; }
Property Value Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class ExampleClass : MonoBehaviour
{
public Button btnMain;
void SomeFunction()
{
//Sets the main button's transition setting to "Color Tint".
btnMain.transition = Selectable.Transition.ColorTint;
}
}
Methods AllSelectablesNoAlloc(Selectable[])
Non allocating version for getting the all selectables. If selectables.Length is less then s_SelectableCount only selectables.Length elments will be copied which could result in a incomplete list of elements.
Declarationpublic static int AllSelectablesNoAlloc(Selectable[] selectables)
Parameters Type Name Description Selectable[] selectables
The array to be filled with current selectable objects
Returns Type Description intThe number of element copied.
Examplesusing UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class Example : MonoBehaviour
{
Selectable[] m_Selectables = new Selectable[10];
//Displays the names of all selectable elements in the scene
public void GetNames()
{
if (m_Selectables.Length < Selectable.allSelectableCount)
m_Selectables = new Selectable[Selectable.allSelectableCount];
int count = Selectable.AllSelectablesNoAlloc(ref m_Selectables);
for (int i = 0; i < count; ++i)
{
Debug.Log(m_Selectables[i].name);
}
}
}
Awake() Declaration
protected override void Awake()
Overrides DoStateTransition(SelectionState, bool)
Transition the Selectable to the entered state.
Declarationprotected virtual void DoStateTransition(Selectable.SelectionState state, bool instant)
Parameters FindSelectable(Vector3)
Finds the selectable object next to this one.
Declarationpublic Selectable FindSelectable(Vector3 dir)
Parameters Type Name Description Vector3 dir
The direction in which to search for a neighbouring Selectable object.
Returns Type Description SelectableThe neighbouring Selectable object. Null if none found.
Examplesusing UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class ExampleClass : MonoBehaviour
{
//Sets the direction as "Up" (Y is in positive).
public Vector3 direction = new Vector3(0, 1, 0);
public Button btnMain;
public void Start()
{
//Finds and assigns the selectable above the main button
Selectable newSelectable = btnMain.FindSelectable(direction);
Debug.Log(newSelectable.name);
}
}
FindSelectableOnDown()
Find the selectable object below this one.
Declarationpublic virtual Selectable FindSelectableOnDown()
Returns Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class Example : MonoBehaviour
{
public Button startButton;
// Disables the selectable UI element directly below the Start Button
public void IgnoreSelectables()
{
//Finds the selectable UI element below the start button and assigns it to a variable of type "Selectable"
Selectable secondButton = startButton.FindSelectableOnDown();
//Disables interaction with the selectable UI element
secondButton.interactable = false;
}
}
FindSelectableOnLeft()
Find the selectable object to the left of this one.
Declarationpublic virtual Selectable FindSelectableOnLeft()
Returns Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class ExampleClass : MonoBehaviour
{
public Button btnMain;
// Disables the selectable UI element directly to the left of the Start Button
public void IgnoreSelectables()
{
//Finds the selectable UI element to the left the start button and assigns it to a variable of type "Selectable"
Selectable secondButton = startButton.FindSelectableOnLeft();
//Disables interaction with the selectable UI element
secondButton.interactable = false;
}
}
FindSelectableOnRight()
Find the selectable object to the right of this one.
Declarationpublic virtual Selectable FindSelectableOnRight()
Returns Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class ExampleClass : MonoBehaviour
{
public Button btnMain;
// Disables the selectable UI element directly to the right the Start Button
public void IgnoreSelectables()
{
//Finds the selectable UI element to the right the start button and assigns it to a variable of type "Selectable"
Selectable secondButton = startButton.FindSelectableOnRight();
//Disables interaction with the selectable UI element
secondButton.interactable = false;
}
}
FindSelectableOnUp()
The Selectable object above current
Declarationpublic virtual Selectable FindSelectableOnUp()
Returns Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class ExampleClass : MonoBehaviour
{
public Button btnMain;
// Disables the selectable UI element directly above the Start Button
public void IgnoreSelectables()
{
//Finds the selectable UI element above the start button and assigns it to a variable of type "Selectable"
Selectable secondButton = startButton.FindSelectableOnUp();
//Disables interaction with the selectable UI element
secondButton.interactable = false;
}
}
InstantClearState()
Clear any internal state from the Selectable (used when disabling).
Declarationprotected virtual void InstantClearState()
IsHighlighted()
Returns whether the selectable is currently 'highlighted' or not.
Declarationprotected bool IsHighlighted()
Returns Examples
//Create a UI element. To do this go to Create>UI and select from the list. Attach this script to the UI GameObject to see this script working. The script also works with non-UI elements, but highlighting works better with UI.
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
//Use the Selectable class as a base class to access the IsHighlighted method
public class Example : Selectable
{
//Use this to check what Events are happening
BaseEventData m_BaseEvent;
void Update()
{
//Check if the GameObject is being highlighted
if (IsHighlighted())
{
//Output that the GameObject was highlighted, or do something else
Debug.Log("Selectable is Highlighted");
}
}
}
IsInteractable()
Is the object interactable.
Declarationpublic virtual bool IsInteractable()
Returns Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
public class Example : MonoBehaviour
{
public Button startButton;
void Update()
{
if (!startButton.IsInteractable())
{
Debug.Log("Start Button has been Disabled");
}
}
}
IsPressed()
Whether the current selectable is being pressed.
Declarationprotected bool IsPressed()
Returns OnCanvasGroupChanged() Declaration
protected override void OnCanvasGroupChanged()
Overrides OnDeselect(BaseEventData)
Unset selection and transition to appropriate state.
Declarationpublic virtual void OnDeselect(BaseEventData eventData)
Parameters Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IDeselectHandler //This Interface is required to receive OnDeselect callbacks.
{
public void OnDeselect(BaseEventData data)
{
Debug.Log("Deselected");
}
}
OnDidApplyAnimationProperties() Declaration
protected override void OnDidApplyAnimationProperties()
Overrides OnDisable() Declaration
protected override void OnDisable()
Overrides OnEnable() Declaration
protected override void OnEnable()
Overrides OnMove(AxisEventData)
Determine in which of the 4 move directions the next selectable object should be found.
Declarationpublic virtual void OnMove(AxisEventData eventData)
Parameters Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IMoveHandler
{
//When the focus moves to another selectable object, Invoke this Method.
public void OnMove(AxisEventData eventData)
{
//Assigns the move direction and the raw input vector representing the direction from the event data.
MoveDirection moveDir = eventData.moveDir;
Vector2 moveVector = eventData.moveVector;
//Displays the information in the console
Debug.Log(moveDir + ", " + moveVector);
}
}
OnPointerDown(PointerEventData)
Evaluate current state and transition to pressed state.
Declarationpublic virtual void OnPointerDown(PointerEventData eventData)
Parameters Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IPointerDownHandler// required interface when using the OnPointerDown method.
{
//Do this when the mouse is clicked over the selectable object this script is attached to.
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log(this.gameObject.name + " Was Clicked.");
}
}
OnPointerEnter(PointerEventData)
Evaluate current state and transition to appropriate state. New state could be pressed or hover depending on pressed state.
Declarationpublic virtual void OnPointerEnter(PointerEventData eventData)
Parameters Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IPointerEnterHandler// required interface when using the OnPointerEnter method.
{
//Do this when the cursor enters the rect area of this selectable UI object.
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log("The cursor entered the selectable UI element.");
}
}
OnPointerExit(PointerEventData)
Evaluate current state and transition to normal state.
Declarationpublic virtual void OnPointerExit(PointerEventData eventData)
Parameters Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IPointerExitHandler// required interface when using the OnPointerExit method.
{
//Do this when the cursor exits the rect area of this selectable UI object.
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("The cursor exited the selectable UI element.");
}
}
OnPointerUp(PointerEventData)
Evaluate eventData and transition to appropriate state.
Declarationpublic virtual void OnPointerUp(PointerEventData eventData)
Parameters Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, IPointerUpHandler, IPointerDownHandler// These are the interfaces the OnPointerUp method requires.
{
//OnPointerDown is also required to receive OnPointerUp callbacks
public void OnPointerDown(PointerEventData eventData)
{
}
//Do this when the mouse click on this selectable UI object is released.
public void OnPointerUp(PointerEventData eventData)
{
Debug.Log("The mouse click was released");
}
}
OnSelect(BaseEventData)
Set selection and transition to appropriate state.
Declarationpublic virtual void OnSelect(BaseEventData eventData)
Parameters Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour, ISelectHandler// required interface when using the OnSelect method.
{
//Do this when the selectable UI object is selected.
public void OnSelect(BaseEventData eventData)
{
Debug.Log(this.gameObject.name + " was selected");
}
}
OnTransformParentChanged() Declaration
protected override void OnTransformParentChanged()
Overrides OnValidate() Declaration
protected override void OnValidate()
Overrides Reset() Declaration
protected override void Reset()
Overrides Select()
Selects this Selectable.
Declarationpublic virtual void Select()
Examples
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // required when using UI elements in scripts
using UnityEngine.EventSystems;// Required when using Event data.
public class ExampleClass : MonoBehaviour// required interface when using the OnSelect method.
{
public InputField myInputField;
//Do this OnClick.
public void SaveGame()
{
//Makes the Input Field the selected UI Element.
myInputField.Select();
}
}
Implements
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4