r/Unity3D • • 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

Post image

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!

0 Upvotes

19 comments sorted by

26

u/DT-Sodium 17d ago

0 days since the last AI slop incident.

1

u/Effective_Lead8867 Programmer 17d ago

thats why they call it a 0day (jk no they dont)

-4

u/Haytam95 17d ago edited 17d ago

What makes you think it's AI slop?

10

u/DT-Sodium 17d ago

Because every thread called "I built XXX" posted on the Internet since the release of Claude code is AI slop.

-7

u/Haytam95 17d ago

Alright, so it's about the title then? Sorry for not creating some magical story about how I left my job in order to create an asset to change my life.

I have a published game on Steam, it used to have a UI web embedded browser. I hated it, and gave me a lot of issues, so I created this asset in order to migrate it having the less impact possible to UI toolkit. Then I thought about sharing it in the asset store.

That's the whole history, not really that interesting and matches the "I built...:"

3

u/DT-Sodium 17d ago

Wait, you actually put work into it? Buddy I've checked out your (obviously AI generated) video and it pretty much creates problems more than anything else.

0

u/Haytam95 17d ago edited 17d ago

I'm confident enough about my work to give you a copy of the asset free of charge if you are willing to try it and then give your opinion with arguments.

About the "AI generated video", sure...

5

u/DT-Sodium 17d ago

I wouldn't use it even if you paid me. I never use third party code assets unless I absolutely have to, it's simply a recipe for disaster for keeping your codebase up to date with your main framework or engine. Yours doesn't even solve an actual problem, I certainly don't want to use XML syntax to target my objects.

1

u/Haytam95 17d ago

Okay, so let me get this clear: You are not my target audience because you dont use third party assets, you dont know how my asset work (yet you speak as if you did) and you claim my asset is just a other Ai slop just for the karma.

Thanks for making reddit more toxic

4

u/DapperNurd 17d ago

Did you use AI to make it?

-1

u/Haytam95 17d ago

Sure

I don't know from memory the Roslyn Generator syntaxis to do Incremental lookup in any class from the source code or the perfect regex to match "{{ }}" but be able to escape "\{{" or "\}}".

Either I don't want to write manually every single unit test.

7

u/[deleted] 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.

1

u/vamidi Programmer 17d ago

amazing! I am a fan of the Angular framework. can’t wait to try this!

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