eastrall / rosalina Goto Github PK
View Code? Open in Web Editor NEWRosalina is a code generation tool for Unity's UI documents. It generates C# code-behind script based on a UXML template.
License: MIT License
Rosalina is a code generation tool for Unity's UI documents. It generates C# code-behind script based on a UXML template.
License: MIT License
When I add Roslina to the project with the application that I want to convert to toolkit, I get these errors.
It is the same with 2021.2 and in 2022
Assembly 'Packages/com.eastylabs.rosalina/Editor/Roslyn/Microsoft.CodeAnalysis.CSharp.dll' will not be loaded due to errors:
Reference has errors 'Microsoft.CodeAnalysis'.
Microsoft.CodeAnalysis.Workspaces.dll' will not be loaded due to errors:
Microsoft.CodeAnalysis.Workspaces references strong named System.Runtime.CompilerServices.Unsafe Assembly references: 5.0.0.0 Found in project: 4.0.4.1.
Assembly Version Validation can be disabled in Player Settings "Assembly Version Validation"
Assembly 'Packages/com.eastylabs.rosalina/Editor/Roslyn/Microsoft.CodeAnalysis.VisualBasic.Workspaces.dll' will not be loaded due to errors:
Reference has errors 'Microsoft.CodeAnalysis.Workspaces'.
Assembly 'Packages/com.eastylabs.rosalina/Editor/Roslyn/Microsoft.CodeAnalysis.VisualBasic.dll' will not be loaded due to errors:
Reference has errors 'Microsoft.CodeAnalysis'.
Created new 2021.2.14 project and got errors with nothing installed except Roslina.
I found an interesting bug, while generating some new UIs:
Rosalina somehow generated Binding Files for some pre-packaged uxmls inside of the unity-core. (see Screenshot).
I'm not quite sure how to reproduce this issue, but it happened to me now twice, after restarting unity.
I think, we need something like a Path-Filter on which uxmls to interprete, to prevent things like that from happening.
I suggest., that everything outside of the Assets-Folder should be ignored by default.
So I have some nitpicks with Rosalina, I am going to be more direct than formal so here they are
when I checked the generated partial classes, they seemed to be cast instead of being Qed with generics, is there a reason for not using
generics and casting instead? I think generics will help in the long run
as it says, support for these would be helpful
unity recently released runtime binding, but it's for the 2023 beta/alpha so it can be delayed, also if it would be better to be done manually, then ignore this point
basically instead of having automatic generation for files, have an option to manually generate for them or select which files to generate specifically (maybe even choosing what kind of generation it is like runtime, editor window, etc)
choosing a custom file path would be a QOL change, also having the Rosalina settings SO be in the packages part would be better if possible
Add an editor extension to the unity's menu that allows multiple options on UXML files.
This option allows to generate the code-behind of a UXML template. It can be used for generating code-behind of existing templates.
This option allows to generate a UI script where the developer will be able to code its UI logic.
Is there a way to support using dashes in naming the fields? When I try to modify existing uxml files that use dashes in the names, it does not work. I am talking about when someone names a field something like a label field and they name it main-label which seems to be a kind of standard from many toolkit existing projects that I have found.
At the begining the project was a POC (Proof Of Concept) and the code was dirty and not optimized.
In order to have a clean and readable code, some refactorings are necessary:
class
es / modulesstring
s) with real .NET Type
sRename the `Generate Code-Behind" menu-item into "Generate UI bindings" instead.
I quite like, what this plugin does, but I'm missing some key features to make it better usable in bigger/structured projects:
Namespace-Support
Currently the generated files are part of the default namespace. This works for smaller projects, but not for bigger or better structured ones.
While it's possible to move the UI-Script into a namespace manually, it's impossible to do that reliable for the Bindings-Script, which will be rewritten repeatedly.
There should be some option to generate the Binding-Scripts for a specific namespace.
Idealy, there would even be a support for multiple namespaces, either on folder, or on a VTA by VTA basis.
Pathing Support
Currently the UI-Script and the Bindings-Script are created next to the VTA. While it's possible to move the UI-Script to a different path, Rosalina does not notice, when you move the Bindings-Script and just recreates a new one next to the VTA.
It would be good, if it was possible to move Bindings-Scripts and keep them on a sperate path, enabling the sepparation of VTA and the scripts.
Again Idealy, there would even be a support for multiple target folders, either on folder or on a VTA by VTA basis.
Disabling Rosalino for some VTAs
It would be good, if it was possible to disable auomatic file generation for each VTA.
Especially if you are working with an already existing UI and start using Rosalina at a later point, you might not want to rework all your code and VTAs just to make the generated Bindings-Scripts compile.
Currently, you either have to repeatedly delete the generated Bindings-Scripts or rework everything already existing, if you e.g. used kebab case for the field identifier until starting to use Rosalina.
The same may apply if you are designing VATs which will be used as internal templates/controls, used wihtin other of your VATs.
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:
// CustomComponent.g.cs
public partial class CustomComponent
{
private VisualElement _root;
public CustomComponent(VisualElement root)
{
_root = root;
}
public Button MyButton { get; private set; }
public void Initialize()
{
MyButton = (Button)_root?.Q("MyButton");
}
}
...
// MainUIDocument.g.cs
public partial class MainUIDocument
{
[SerializeField]
private UIDocument _document;
public CustomComponent MyCustomComponent { get; private set; }
public VisualElement Root
{
get
{
return _document?.rootVisualElement;
}
}
public void InitializeDocument()
{
MyCustomComponent = new CustomComponent((VisualElement)Root?.Q("MyCustomComponent"));
}
}
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.
Unity version: 2022.2.9
Rosalina version: 2.0.0
The package isn't working in Unity 2022.2.9 which seems to be related to including netstandard 2.0 files, while Unity is now using netstandard 2.1.
Library\PackageCache\[email protected]\Editor\Lighting\ProbeVolume\ProbeGIBaking.cs(1356,30): error CS0433: The type 'ReadOnlySpan<T>' exists in both 'Rosalina.RoslynLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Library\PackageCache\[email protected]\Runtime\Lighting\DiffusionProfileList.cs(26,31): error CS0433: The type 'ArrayPool<T>' exists in both 'Rosalina.RoslynLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
There would be no errors
I fiddled around with deleting Rosalina.RoslynLibrary.dll
and trying to add individual dlls from nuget but didn't get it to work.
Would support for unity 2019 be possible?
I keep getting errors when trying to import it into unity 2019.4.31
Library\PackageCache\com.eastylabs.rosalina@e5b86250e5\Editor\Scripts\Generator\RosalinaBindingsGenerator.cs(16,58): error CS1525: Invalid expression term ''
Library\PackageCache\com.eastylabs.rosalina@e5b86250e5\Editor\Scripts\Generator\RosalinaBindingsGenerator.cs(16,58): error CS1646: Keyword, identifier, or string expected after verbatim specifier: @
Library\PackageCache\com.eastylabs.rosalina@e5b86250e5\Editor\Scripts\Generator\RosalinaBindingsGenerator.cs(16,141): error CS1010: Newline in constant
Library\PackageCache\com.eastylabs.rosalina@e5b86250e5\Editor\Scripts\Generator\RosalinaBindingsGenerator.cs(26,1): error CS1010: Newline in constant
Library\PackageCache\com.eastylabs.rosalina@e5b86250e5\Editor\Scripts\Generator\RosalinaBindingsGenerator.cs(26,3): error CS1002: ; expected
Library\PackageCache\com.eastylabs.rosalina@e5b86250e5\Editor\Scripts\Parsing\RosalinaUXMLParser.cs(16,15): error CS1003: Syntax error, '(' expected
Library\PackageCache\com.eastylabs.rosalina@e5b86250e5\Editor\Scripts\Parsing\RosalinaUXMLParser.cs(16,72): error CS1026: ) expected
A NullReferenceException
is thrown when the user selects Rosalina's menu items (Assets/Rosalina/Generate *) while no asset is selected.
Setup some guides to get started with Rosalina
Unity 2021 supports Source Generators:
Instead of having to manually click "generate", this would just generate the code when compiling, meaning your assets would always be in sync with your generated code.
Version: 1.2.0
When using kebab-case
names in visual elements, such as:
<ui:UXML xmlns:ui="UnityEngine.UIElements" ...>
<ui:VisualElement>
<ui:Button text="Button text" name="some-button" />
</ui:VisualElement>
</ui:UXML>
Rosalina binding generator generates bad query names in auto-generated code:
public Button SomeButton { get; private set; }
...
public void InitializeDocument()
{
SomeButton = (Button)Root?.Q("SomeButton");
}
And then throws an NullReferenceException
when interacting with the property.
Rosalina bindings generator should generate the appropriate query:
public Button SomeButton { get; private set; }
...
public void InitializeDocument()
{
SomeButton = (Button)Root?.Q("some-button");
}
kebab-case
Might be related to this statement:
We are using the Name
property, which should be only used for generating the elements properties. Instead, I believe we should use the OriginalName
since it contains the element's raw name as described in UXML.
Rosalina/Editor/Scripts/Generator/UIProperty.cs
Lines 24 to 40 in e5b8625
I think about using this package inside EditorWindow but cannot find a way how I can map UIDocument and EditorWindow.
Unity version: 2021.3.16f1
Rosalina version: 2.0.0
When creating an UIDocument
inside an Editor
folder for editor extensions, unity places the UIDocument
inside the Assembly-CSharp-Editor
and the generated file is in the Assembly-CSharp
project (folder: Assets/Rosalina/AutoGenerated
)
Two partial
classes cannot be in two different project, they must be in the same project.
Editor
folder in Assets
folder.UIDocument
in the Editor
folder.UIDocument
-> Rosalina
-> Generate UI Script
OnCreateGUI()
method:No defining declaration found for implementing declaration of partial method.
The following C# error appears:
No defining declaration found for implementing declaration of partial method.
There should not be any error.
A possible solution would be to have the generated file next to the UIDocument
definition OR when dealing with an editor extension, create an Editor
folder inside Assets/Rosalina/AutoGenerated
folder.
At this moment, Rosalina generates private
fields for that represents the named UI components defined in the UXML template.
But if we want to interect with properties within another document, a public
field or property is required. Thus, I believe the use of public
readonly property could be interesting.
public
to grant access to the property.
"readonly" to prevent the user to reassign the inner UI field.
This would give us something like:
// MyDocument.g.cs
public partial class MyDocument
{
// Root property has been omitted
public Button MyButton { get; private set; }
public void InitializeDocument()
{
MyButton = (UnityEngine.UIElements.Button)Root?.Q("MyButton");
}
}
In the extension we will be able to use the property
.
public partial class MyDocument
{
private void OnEnable()
{
MyButton.clicked += OnClicked;
}
private void OnClicked()
{
// Do something
}
}
When using a MyDocument
instance, you'll be able to calls the MyButton
property.
// other component
public class OtherComponent : MonoBehavior
{
private void OnEnable()
{
var myDocument = new MyDocument();
myDocument.MyButton.text = "Hello world!"; // OK !
myDocument.MyButton = new UnityEngine.UIElements.Button(); // KO !
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.