All Projects → Eastrall → Rosalina

Eastrall / Rosalina

Licence: MIT, Unknown licenses found Licenses found MIT LICENSE Unknown LICENSE.meta
Rosalina is a code generation tool for Unity's UI documents. It generates C# code-behind script based on a UXML template.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to Rosalina

CategoryTool
Unity Editor tool to create Categories in the Hierarchy. The Categories work as dividers between GameObjects.
Stars: ✭ 47 (-17.54%)
Mutual labels:  unity-editor, unity-plugin
TsukiSuite
A toolsuite created to make Unity development easier
Stars: ✭ 23 (-59.65%)
Mutual labels:  unity-editor, unity-plugin
Smart-Inspector
Fluent re-take on Unity Inspector UX. Packed with QoL improvements.
Stars: ✭ 680 (+1092.98%)
Mutual labels:  ui-toolkit, ui-elements
Awesome Roslyn
Curated list of awesome Roslyn books, tutorials, open-source projects, analyzers, code fixes, refactorings, and source generators
Stars: ✭ 395 (+592.98%)
Mutual labels:  roslyn, code-generation
ElementAnimationToolkit
A collection of Unity UIElements animation extension methods, new animated elements, and examples.
Stars: ✭ 51 (-10.53%)
Mutual labels:  unity-editor, uielements
Polygen
PolyGen is a code generator that produces database schema, ORM layer, REST API and a (coming soon — stay tuned!) single-page web UI for your business model.
Stars: ✭ 19 (-66.67%)
Mutual labels:  roslyn, code-generation
Mappinggenerator
🔄 "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
Stars: ✭ 831 (+1357.89%)
Mutual labels:  roslyn, code-generation
DialogueGraph
Open-source node-based tool for developing branching conversation trees
Stars: ✭ 133 (+133.33%)
Mutual labels:  unity-editor, unity-plugin
typed-astunparse
Python 3 AST unparser with type comments support.
Stars: ✭ 27 (-52.63%)
Mutual labels:  code-generation
fling
A fluent API generator
Stars: ✭ 20 (-64.91%)
Mutual labels:  code-generation
FSharpWrap
Utility that automatically generates F# modules and functions based on your F# project file's references
Stars: ✭ 14 (-75.44%)
Mutual labels:  code-generation
UnityEventDrawerEx
This plugin extends the UnityEventDrawer to display runtime calls in the inspector.
Stars: ✭ 57 (+0%)
Mutual labels:  unity-editor
granate
Code generator for graphql
Stars: ✭ 21 (-63.16%)
Mutual labels:  code-generation
code-fold
Write the pattern, then let your code write itself.
Stars: ✭ 13 (-77.19%)
Mutual labels:  code-generation
AUXify
Introduces macro/meta annotations @ aux, @ self, @ instance, @ apply, @ delegated, @ syntax and String-based type class LabelledGeneric
Stars: ✭ 25 (-56.14%)
Mutual labels:  code-generation
toast
Plugin-driven CLI utility for code generation using Go source as IDL
Stars: ✭ 52 (-8.77%)
Mutual labels:  code-generation
gonstructor
A command-line tool to generate a constructor for the struct.
Stars: ✭ 55 (-3.51%)
Mutual labels:  code-generation
t4-templates-unity3d
T4 Text Template Processor for Unity3D
Stars: ✭ 75 (+31.58%)
Mutual labels:  unity-editor
Procedural-City-Generator
This unity editor script can generate procedural cities in Unity 3D editor itself so there is no need to design the game world in external tools. City is generated at predefined or random points by premetives.
Stars: ✭ 18 (-68.42%)
Mutual labels:  unity-plugin
cscg
Code Generation as a Dual Task of Code Summarization.
Stars: ✭ 28 (-50.88%)
Mutual labels:  code-generation

Rosalina

openupm

Rosalina is a code generation tool for Unity's UI documents. It allows developers to generate C# UI bindings and code-behind scripts based on a UXML template.

How to install

Rosalina can either be installed via OpenUPM: https://openupm.com/packages/com.eastylabs.rosalina/ Or by using the following git repository: https://github.com/Eastrall/Rosalina.git

For a more detailed explanation, see our documentation.

How to use

We provided some introduction to Rosalina's file generation in our documentation. Just follow this link.

How it works

Rosalina watches your changes related to all *.uxml files, parses its content and generates the according C# UI binding code based on the element's names.

Take for instance the following UXML template:

SampleDocument.uxml

<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements"
         xsi="http://www.w3.org/2001/XMLSchema-instance"
         engine="UnityEngine.UIElements" editor="UnityEditor.UIElements"
         noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <ui:VisualElement>
        <ui:Label text="Label" name="TitleLabel"/>
        <ui:Button text="Button" name="Button"/>
    </ui:VisualElement>
</ui:UXML>

Rosalina's AssetProcessor will automatically genearte the following C# UI bindings script:

SampleDocument.g.cs

// <autogenerated />
using UnityEngine;
using UnityEngine.UIElements;

public partial class SampleDocument
{
    [SerializeField]
    private UIDocument _document;
    public Label TitleLabel { get; private set; }

    public Button Button { get; private set; }

    public VisualElement Root
    {
        get
        {
            return _document?.rootVisualElement;
        }
    }

    public void InitializeDocument()
    {
        TitleLabel = (Label)Root?.Q("TitleLabel");
        Button = (Button)Root?.Q("Button");
    }
}

⚠️ This script behing an auto-generated code based on the UXML template, you should not write code inside this file. It will be overwritten everytime you update your UXML template file.

Rosalina provides a context-menu option to generate a C# UI script where you can place your UI related code without the risk of behing overwritten by Rosalina's asset processor. Just right click on the UXML and access Rosalina menu-item, then select Genearte UI script.

image

This option will generate the following code:

SampleDocument.cs

using UnityEngine;

public partial class SampleDocument : MonoBehaviour
{
    private void OnEnable()
    {
        InitializeDocument();
    }
}

Notes

As pointed out by JuliaP_Unity on Unity Forums the document initialization process (element queries) should be done on the OnEnable() hook, since the UIDocument visual tree asset is instancied at this moment. Thank you for the tip!

According to Unity's UI Builder warnings, a VisualElement name can only contains letters, numbers, underscores and dashes. Since a name with dashes is not a valid name within a C# context, during the code generation process, Rosalina will automatically convert dashed-names into PascalCase. Meaning that if you have the following UXML:

<ui:VisualElement>
    <ui:Button text="Button" name="confirm-button"/>
</ui:VisualElement>

Rosalina will generate the following property:

public Button ConfirmButton { get; private set; }

In case you already have a ConfirmButton as a VisualElement name, do not worry, Rosalina will detect it for you during the code generation process and throw an error letting you know there is a duplicate property in your UXML document.

Known limitations

For now, Rosalina only generates the UI Document bindings and code behding scripts based on the UI element names. You still need to create on your own the GameObject with a UIDocument component and then add the UI script (not the UI binding scripts).

ℹ️ In next versions, we could think of an extension that automatically creates a GameObject with the UI script attached to it. 😄

Final words

If you like the project, don't hesitate to contribute! All contributions are welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].