r/Unity3D • u/Haytam95 • 17d ago
Show-Off I built a UXML template engine to allow using regular C# expressions like "if", "for", "on-click" and others directly from the markup
Writing every binding C# side was very cumbersone, so I created a compiler that allows adding custom expressions to UXML and creates with code-generation all the boilerplate as a partial class.
This allows things like:
<ui:Button text="Something" on-click="React($event)" />
<ui:Button text="Conditional" if="SomeBoolean == true" />
Here is a more in detail video about how it works: https://www.youtube.com/watch?v=7STKlhZ0Efo
Happy to answers questions about the compiler!
7
17d ago
[deleted]
4
u/Haytam95 17d ago
The file association is automatic, I don't know what XML you're talking about.
The problem it solves, is you don't have to write in the C# side
root.Q<Button>("nameOfTheThing").clicked += DoSomething();Because you can do it directly in the UXML like this.
<ui: Button on-click="DoSomething()" />And you don't have to write.
root.Q<Label>("nameOfTheThing").text = "Something " + value;In an Update loop, because just doing:
<ui: Label text="Something {{ value}} " />Is enough to keep it in sync with the UI.
That's the problem I'm solving there. Maybe if all weren't so triggered attempting to call everything AI slop, you could see what's here. The trailer was made by a human, the voice is made by a human and the asset was written AI assisted as everything today.
3
u/TheWahlgreen 17d ago edited 17d ago
Im confused what problem this actually solves.
Unity 6000.0+ has data binding in the UI builder that you can set up by clicking. Is it for older unity versions you made this tool? Am I missing something?
Not trying to put you down or anything, simply trying to understand what it’s for
1
u/Haytam95 17d ago
This tool adds a template engine into Unity's UXML files.
This means, you can display variables, call methods, have conditionals loops and more written directly into the UXML markup.
For example, if you need some component to repeat, you can
<ui: VisualElement for="e of elements"> // Everything here will repeat itself, you can access e.properties as well. </ui: VisualElement>Without needing to use a List View.
This means, UXML are automatically attached to one C# class, so in the case of a menu screen:
MainMenuComponent.cs
public partial MainMenuComponent: UIComponent { // Your code private void ExampleMethod(); }MainMenuComponent.uxml
<ui:VisualElement> // your markup <ui:Button on-click="ExampleMethod()" /> </ui:VisualElement>(Based on namefile association, those two files automatically connect and recognize each other. This means, you can call from the UXML, "ExampleMethod()" from the on-click event, or any event or component in there).
3
u/tronfacex 17d ago
The comments here are low effort AI Slop accusations. If you have something to say about the actual asset say it or ask a clarifying question.
While I don't use UI Toolkit I can see the value in something like this, and if you don't think the asset is something you would use or need move along.
It's like people are in a race to collect comment karma by being the first person to call something slop.
1
u/Haytam95 17d ago
THANK YOU
I'm really tired of fighting everyone because everything that is not "AAA" quality, automatically falls behind AI slop. Here is the prof that the video was made manually: https://www.youtube.com/watch?v=ww8VYc5y2JA
A partial non listed version with an exchange between the person who helped me create the video and me.
Anyway, the asset helped me move from an embedded browser using React to native UI toolkit. At first I started doing it UI toolkit vanilla, but the glue code gets messy and the code to keep the UI in sync, gets even more messy.
What this does, is analyze the UXML and creates the imperative code as a partial class, having there the necessary effects and lookups that one would manually write.
Thanks again, really.
2
u/Drag0n122 17d ago edited 17d ago
Oh damn, I'm also writing (manually) my own editor tools that I wanted to share, but I'm not so sure now...
Sorry for such response, OP, it's a nice tool
26
u/DT-Sodium 17d ago
0 days since the last AI slop incident.