Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Focusable

Base class for objects that can get the focus.
Read time 2 minutesLast updated 2 days ago

Definition

public abstract class Focusable : CallbackEventHandler, IEventHandler

Remarks

The focus is used to designate an element that will receive keyboard and navigation events.
You can retrieve a panel's current focused element using its FocusController's _focusedElement property.

Examples

using UnityEngine;using UnityEngine.UIElements;[RequireComponent(typeof(UIDocument))]public class FocusExample : MonoBehaviour{ void OnEnable() { var startGameButton = GetComponent<UIDocument>().rootVisualElement.Q<Button>("StartGame"); startGameButton.RegisterCallback<FocusInEvent>(ev => { Debug.Log("FocusInEvent: button is focused and can be activated with keyboard or gamepad input."); }); Debug.Log("Calling startGameButton.Focus()."); startGameButton.Focus(); var isFocused = startGameButton.focusController.focusedElement == startGameButton; Debug.Log("Immediately after startGameButton.Focus(): isFocused=" + isFocused); // Expected output: // > Calling startGameButton.Focus(). // > FocusInEvent: button is focused and can be activated with keyboard or gamepad input. // > Immediately after startGameButton.Focus(): isFocused=true }}

Properties

Property

Description

canGrabFocusWhether the element can be focused.
delegatesFocusWhether the element delegates the focus to its children.
focusableWhether an element can potentially receive focus.
focusControllerReturns the focus controller for this element.
tabIndexAn integer used to sort focusable elements in the focus ring. Must be greater than or equal to zero.

Methods

Method

Description

BlurTell the element to release the focus.
FocusAttempts to give the focus to this element.

Inheritance