The VisualElementPicker
attribute simplifies the assignment of visual element references for your UI script managers
. Using this attribute, you can easily select visual elements associated with the UI document by specifying them as strings within the inspector.
- Clone or download this repository.
- Open your Unity project.
- Drag and drop the package into your
Assets
folder orPackages
folder.
- Open the Unity Package Manager:
Window -> Package Manager
. - Click on the
+
button in the top left corner. - Select
Add package from git URL...
. - Paste the following URL:
https://github.com/TitanX101/VisualElementPicker.git
- Click
Add
to install the package directly from the repository.
- Apply the
VisualElementPicker
attribute forstring
types and specify if you want to skip null elements (i.e., visual elements without names). This attribute requires aUIDocument
component to be present on the same GameObject where the script with this attribute is attached. - From the picker, you can apply search filters either by name or by type directly. To search by type, use the same format as in Unity, for example, "t: MyVisualElementType".
Here are some examples of how to use the VisualElementPicker
attribute:
[VisualElementPicker]
public string myElement;
[VisualElementPicker(TargetType = typeof(MyVisualElementType))]
public string myTypedElement;
[VisualElementPicker(targetType: typeof(Button), skipEmpty: true)]
public string myFilteredElement;
[VisualElementPicker(true)]
public string myElementSkippingEmpty;
Although I'm not sure if this is possible yet, it would be interesting to be able to assign visual element references and ensure they don't get lost once their names are changed from the UI Builder. So this will be a POSSIBLE task to do.