Making The UI interactable with C#
The UI Builder and your UXML document only handle the visual properties of your UI. While you can assign some basic responses (like changing visuals on hover) through the use of style sheets, you will need to create C# scripts to handle any logic or events related to your UI.
The UIElements namespaces
To be able to write code that interfaces with UI Documents, you must use the UnityEngine.UIElements
namespace. If you are using the UI Toolkit to make editor UI, you may also need the UnityEditor.UIElements
namespace.
Note
For more information about the UnityEngine.UIElements
and UnityEditor.UIElements
namespaces, see the following resource: https://docs.unity3d.com/Packages/com.unity.ui@1.0/api/UnityEditor.UIElements.html.
Getting a reference to UI Documents variables
Within your C# script, you can create a reference variable to a UIDocument
type. You can assign this variable in the same way you would generally assign a variable of...