docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class Selectable

    Inheritance
    object
    Object
    Component
    Behaviour
    MonoBehaviour
    UIBehaviour
    Selectable
    TMP_Dropdown
    TMP_InputField
    Button
    Dropdown
    InputField
    Scrollbar
    Slider
    Toggle
    Implements
    IMoveHandler
    IPointerDownHandler
    IPointerUpHandler
    IPointerEnterHandler
    IPointerExitHandler
    ISelectHandler
    IDeselectHandler
    IEventSystemHandler
    Inherited Members
    UIBehaviour.Start()
    UIBehaviour.OnDestroy()
    UIBehaviour.IsActive()
    UIBehaviour.OnRectTransformDimensionsChange()
    UIBehaviour.OnBeforeTransformParentChanged()
    UIBehaviour.OnCanvasHierarchyChanged()
    UIBehaviour.IsDestroyed()
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(string, float)
    MonoBehaviour.InvokeRepeating(string, float, float)
    MonoBehaviour.CancelInvoke(string)
    MonoBehaviour.IsInvoking(string)
    MonoBehaviour.StartCoroutine(string)
    MonoBehaviour.StartCoroutine(string, object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(string)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(object)
    MonoBehaviour.destroyCancellationToken
    MonoBehaviour.useGUILayout
    MonoBehaviour.didStart
    MonoBehaviour.didAwake
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, out Component)
    Component.TryGetComponent<T>(out T)
    Component.GetComponent(string)
    Component.GetComponentInChildren(Type, bool)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(bool)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, bool)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(bool)
    Component.GetComponentsInChildren<T>(bool, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type, bool)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>(bool)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, bool)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(bool)
    Component.GetComponentsInParent<T>(bool, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.GetComponentIndex()
    Component.CompareTag(string)
    Component.CompareTag(TagHandle)
    Component.SendMessageUpwards(string, object, SendMessageOptions)
    Component.SendMessageUpwards(string, object)
    Component.SendMessageUpwards(string)
    Component.SendMessageUpwards(string, SendMessageOptions)
    Component.SendMessage(string, object)
    Component.SendMessage(string)
    Component.SendMessage(string, object, SendMessageOptions)
    Component.SendMessage(string, SendMessageOptions)
    Component.BroadcastMessage(string, object, SendMessageOptions)
    Component.BroadcastMessage(string, object)
    Component.BroadcastMessage(string)
    Component.BroadcastMessage(string, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(object)
    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, int)
    Object.InstantiateAsync<T>(T, int, Transform)
    Object.InstantiateAsync<T>(T, int, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion)
    Object.InstantiateAsync<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>)
    Object.InstantiateAsync<T>(T, int, Transform, ReadOnlySpan<Vector3>, ReadOnlySpan<Quaternion>, CancellationToken)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Scene)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, bool)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, bool)
    Object.Destroy(Object, float)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, bool)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.FindObjectsOfType(Type, bool)
    Object.FindObjectsByType(Type, FindObjectsSortMode)
    Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, float)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectsByType<T>(FindObjectsSortMode)
    Object.FindObjectsOfType<T>(bool)
    Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
    Object.FindObjectOfType<T>()
    Object.FindObjectOfType<T>(bool)
    Object.FindFirstObjectByType<T>()
    Object.FindAnyObjectByType<T>()
    Object.FindFirstObjectByType<T>(FindObjectsInactive)
    Object.FindAnyObjectByType<T>(FindObjectsInactive)
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.FindFirstObjectByType(Type)
    Object.FindAnyObjectByType(Type)
    Object.FindObjectOfType(Type, bool)
    Object.FindFirstObjectByType(Type, FindObjectsInactive)
    Object.FindAnyObjectByType(Type, FindObjectsInactive)
    Object.ToString()
    Object.name
    Object.hideFlags
    object.Equals(object, object)
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    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
    protected Selectable()

    Fields

    m_CurrentIndex

    Declaration
    protected int m_CurrentIndex
    Field Value
    Type Description
    int

    s_SelectableCount

    Declaration
    protected static int s_SelectableCount
    Field Value
    Type Description
    int

    s_Selectables

    Declaration
    protected static Selectable[] s_Selectables
    Field Value
    Type Description
    Selectable[]

    Properties

    allSelectableCount

    How many selectable elements are currently active.

    Declaration
    public static int allSelectableCount { get; }
    Property Value
    Type Description
    int

    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
    Type Description
    List<Selectable>

    allSelectablesArray

    Copy of the array of all the selectable objects currently active in the scene.

    Declaration
    public static Selectable[] allSelectablesArray { get; }
    Property Value
    Type Description
    Selectable[]
    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.

    Declaration
    public AnimationTriggers animationTriggers { get; set; }
    Property Value
    Type Description
    AnimationTriggers
    Remarks

    Modifications will not be visible if transition is not Animation.

    animator

    Convenience function to get the Animator component on the GameObject.

    Declaration
    public Animator animator { get; }
    Property Value
    Type Description
    Animator
    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.

    Declaration
    public ColorBlock colors { get; set; }
    Property Value
    Type Description
    ColorBlock
    Remarks

    Modifications will not be visible if transition is not ColorTint.

    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
    Type Description
    Selectable.SelectionState

    image

    Convenience function that converts the referenced Graphic to a Image, if possible.

    Declaration
    public Image image { get; set; }
    Property Value
    Type Description
    Image

    interactable

    Is this object interactable.

    Declaration
    public bool interactable { get; set; }
    Property Value
    Type Description
    bool
    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.

    Declaration
    public Navigation navigation { get; set; }
    Property Value
    Type Description
    Navigation
    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.

    Declaration
    public SpriteState spriteState { get; set; }
    Property Value
    Type Description
    SpriteState
    Remarks

    Modifications will not be visible if transition is not SpriteSwap.

    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.

    Declaration
    public Graphic targetGraphic { get; set; }
    Property Value
    Type Description
    Graphic
    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.

    Declaration
    public Selectable.Transition transition { get; set; }
    Property Value
    Type Description
    Selectable.Transition
    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.

    Declaration
    public static int AllSelectablesNoAlloc(Selectable[] selectables)
    Parameters
    Type Name Description
    Selectable[] selectables

    The array to be filled with current selectable objects

    Returns
    Type Description
    int

    The number of element copied.

    Examples
    using 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
    UIBehaviour.Awake()

    DoStateTransition(SelectionState, bool)

    Transition the Selectable to the entered state.

    Declaration
    protected virtual void DoStateTransition(Selectable.SelectionState state, bool instant)
    Parameters
    Type Name Description
    Selectable.SelectionState state

    State to transition to

    bool instant

    Should the transition occur instantly.

    FindSelectable(Vector3)

    Finds the selectable object next to this one.

    Declaration
    public Selectable FindSelectable(Vector3 dir)
    Parameters
    Type Name Description
    Vector3 dir

    The direction in which to search for a neighbouring Selectable object.

    Returns
    Type Description
    Selectable

    The neighbouring Selectable object. Null if none found.

    Remarks

    The direction is determined by a Vector3 variable.

    Examples
    using 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.

    Declaration
    public virtual Selectable FindSelectableOnDown()
    Returns
    Type Description
    Selectable
    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.

    Declaration
    public virtual Selectable FindSelectableOnLeft()
    Returns
    Type Description
    Selectable
    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.

    Declaration
    public virtual Selectable FindSelectableOnRight()
    Returns
    Type Description
    Selectable
    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

    Declaration
    public virtual Selectable FindSelectableOnUp()
    Returns
    Type Description
    Selectable
    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).

    Declaration
    protected virtual void InstantClearState()

    IsHighlighted()

    Returns whether the selectable is currently 'highlighted' or not.

    Declaration
    protected bool IsHighlighted()
    Returns
    Type Description
    bool
    Remarks

    Use this to check if the selectable UI element is currently highlighted.

    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.

    Declaration
    public virtual bool IsInteractable()
    Returns
    Type Description
    bool
    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.

    Declaration
    protected bool IsPressed()
    Returns
    Type Description
    bool

    OnCanvasGroupChanged()

    Declaration
    protected override void OnCanvasGroupChanged()
    Overrides
    UIBehaviour.OnCanvasGroupChanged()

    OnDeselect(BaseEventData)

    Unset selection and transition to appropriate state.

    Declaration
    public virtual void OnDeselect(BaseEventData eventData)
    Parameters
    Type Name Description
    BaseEventData eventData
    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
    UIBehaviour.OnDidApplyAnimationProperties()

    OnDisable()

    Declaration
    protected override void OnDisable()
    Overrides
    UIBehaviour.OnDisable()

    OnEnable()

    Declaration
    protected override void OnEnable()
    Overrides
    UIBehaviour.OnEnable()

    OnMove(AxisEventData)

    Determine in which of the 4 move directions the next selectable object should be found.

    Declaration
    public virtual void OnMove(AxisEventData eventData)
    Parameters
    Type Name Description
    AxisEventData eventData
    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.

    Declaration
    public virtual void OnPointerDown(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData
    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.

    Declaration
    public virtual void OnPointerEnter(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData
    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.

    Declaration
    public virtual void OnPointerExit(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData
    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.

    Declaration
    public virtual void OnPointerUp(PointerEventData eventData)
    Parameters
    Type Name Description
    PointerEventData eventData
    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.

    Declaration
    public virtual void OnSelect(BaseEventData eventData)
    Parameters
    Type Name Description
    BaseEventData eventData
    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
    UIBehaviour.OnTransformParentChanged()

    OnValidate()

    Declaration
    protected override void OnValidate()
    Overrides
    UIBehaviour.OnValidate()

    Reset()

    Declaration
    protected override void Reset()
    Overrides
    UIBehaviour.Reset()

    Select()

    Selects this Selectable.

    Declaration
    public 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

    IMoveHandler
    IPointerDownHandler
    IPointerUpHandler
    IPointerEnterHandler
    IPointerExitHandler
    ISelectHandler
    IDeselectHandler
    IEventSystemHandler
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)