Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


FocusInEvent

Event sent immediately before an element gains focus. This event trickles down and bubbles up.
Read time 2 minutesLast updated 4 days ago

Definition

public class FocusInEvent : FocusEventBase<FocusInEvent>, IDisposable, IFocusEvent

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 }}

Constructors

Constructor

Description

FocusInEvent()Constructor.

Methods

Method

Description

InitResets the event members to their initial values.

Inheritance