ErnSur / UI-Toolkit-Plus

Boilerplate Code Generation, Tabs, Reorderable Manipulator, Built-in USS Exporter
MIT License
182 stars 8 forks source link

Binding script automatic generation #3

Closed Shaun-Fong closed 1 year ago

Shaun-Fong commented 1 year ago

@ErnSur hi , thanks for this useful ui toolkit extension.

try this out

I add script automatic generation feature and I think this way faster than alt+c copy and paste .

If you think this great I will optimize the code then pull request.

Right Click any UXML files , and click UIToolkit->GenerateBinding .

If generated before , it also scan all scripts in project , find the right file (By file name like : UXML File Name+"Binding.cs") and update.

Shaun-Fong commented 1 year ago

image image Bing the data

ErnSur commented 1 year ago

Hi @Shaun-Fong, great to see someone using this lib and even contributing.

This feature is something I thought about adding at the beginning but scraped it for a less complex solution- in the form of QAttribute. Now that I got back to this topic, I did some thinking and R&D and I think that it still might be an interesting addition to the library, although it would require a more complex implementation than what I can see in your fork.

If you are interested I can write down the specifications for this feature and explain the reasoning behind it. We could work on it together, just let me know if you are interested in this form of collaboration.

Shaun-Fong commented 1 year ago

If you are interested I can write down the specifications for this feature and explain the reasoning behind it. We could work on it together, just let me know if you are interested in this form of collaboration.

of course! that sounds great!

ErnSur commented 1 year ago

Query assignment generation feature

Purpose:

automate referencing named elements from UXML so that the user doesn't have to copy and paste names from VisualTreeAsset and write query calls each time the element name is modified or added.

Code generation

Given the following UXML:

<ui:VisualElement>
    <ui:Label name="title" />
</ui:VisualElement>
<ui:VisualElement name="menu">
    <ui:Button name="confirm-button" />
</ui:VisualElement>

We generate something like:

partial class CodeGenExample
{
    private Label title;
    private VisualElement menu;
    private Button confirmButton;

    private void AssignQueryResults(VisualElement root)
    {
        title = root.Q<Label>("title");
        menu = root.Q<VisualElement>("menu");
        confirmButton = root.Q<Button>("confirm-button");
    }
}

Specifications of the generated class

Open Questions:

ErnSur commented 1 year ago

Added to develop