-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate bindings for custom uxml components #25
Comments
At the moment, Rosalina supports only native types: Rosalina/Editor/Scripts/Generator/UIPropertyTypes.cs Lines 7 to 30 in 9ed4c72
I believe this is a good idea to add support of custom components, let's plan this for next releases. Thanks for the suggestion! |
The empty constructors pose a chance to break some code: Defining empty constructors means the other sides of partial implementations can't define them. Anyone currently defining the empty constructor in their app-level code will break. I'm not entirely sure how people use Rosalina. If people bake a ton of logic in their partial implementations, then they'd probably want to write some code in the default constructor. If people use it as a pure binding layer, then they most likely wouldn't care to lose access to the default constructor. The other thing I see, which I missed as well, is invoking |
In the implementation I posted, the code for the composed component was purpose built for it being composed, which lets the default constructors go undefined. I think if you try to make it generalized for both use cases (top-level vs. composed), it's going to be a game of compromise. I'm not familiar with how the auto-generation code works, but maybe you can generate different versions of the file based on it's usage. In your example above, when the autogeneration code gets to Menu.uxml, it'll see that it contains a MenuItems template. Instead of generating the default MenuItems.g.cs, you could generate a MenuItems.Component.g.cs that only has a single constructor expecting a VisualElement. And when the code generation gets to MenuItems.uxml, it'll generate the default MenuItems.g.cs, which can be used as a normal top-level ui component. This way, the empty constructors are left undefined and everyone can continue using Rosalina as is with the choice to opt in to the newly generated Component.g.cs files.
|
You are correct, the default constructor generation is a mistake. I thought that without a default constructor, Unity wouldn't be able to instanciate the
The code generation mechanism is triggered by uxml file. Which means that every uxml file is treated one by one. Thus looking for what uxml is a component wouldn't work in that case. Another approach would be to have something more "manual" which could be integrated along with the suggestion made on issue #26 : Manual generation By doing a right-click on the UXML file, you could :
All this would be stored in the |
Solved in #27, see release : https://github.com/Eastrall/Rosalina/releases/tag/v4.0.0 |
Unity supports re-use of uxml components in other uxml components. Rosalina doesn't generate bindings for these custom uxml components.
Pseudo-ish code for an idea about what to generate:
In general, I have uxml components that will never be a top-level UI element. They will always be composed by something else, so their
[SerializeField] UIDocument _document
field is unnecessary.The text was updated successfully, but these errors were encountered: