Code Monkey home page Code Monkey logo

rosalina's People

Contributors

blepmlem avatar eastrall avatar siglocpp avatar trondtactile avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rosalina's Issues

Errors when adding to project.

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.

Bug: Binding-Scripts get generated for Packaged UXMLs

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).
image

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.

Some of my recommendations for Rosalina

So I have some nitpicks with Rosalina, I am going to be more direct than formal so here they are

Use generics instead of casting

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

Support for Editor Inspectors, Property drawers and etc

as it says, support for these would be helpful

(Maybe?) support for the new runtime binding

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

Manual generation

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)

Custom file path

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 editor extension when right-clicking on a UXML file

Description

Add an editor extension to the unity's menu that allows multiple options on UXML files.

Options

Generate Code-Behind ✔️

This option allows to generate the code-behind of a UXML template. It can be used for generating code-behind of existing templates.

Generate UI script ✔️

This option allows to generate a UI script where the developer will be able to code its UI logic.

Feature Request

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.

Code cleaning

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:

  • Split parsing and generation process in independent classes / modules
  • Create helpers that generates the necessary components for generated UI files
  • Map UXML node types (strings) with real .NET Types
  • Clean parsing process

Feature Request: Namespace and Pathing Support

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.

Generate bindings for custom uxml components

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.

Problems with package in 2022.2.9

🪲 Bug Report

Unity version: 2022.2.9
Rosalina version: 2.0.0

Description

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.

Steps to Reproduce

  1. Add package via git url to Unity 2022.2.9

Current Behavior

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'

Expected Behavior

There would be no errors

Possible Solution

I fiddled around with deleting Rosalina.RoslynLibrary.dll and trying to add individual dlls from nuget but didn't get it to work.

Support for unity 2019

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

Setup guides

Description

Setup some guides to get started with Rosalina

🐞 [BUG] - Issue generating properties assignment for elements with kebab-case names

🐞Bug Report

Version: 1.2.0

Current behavior

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.

Expected Behavior

Rosalina bindings generator should generate the appropriate query:

public Button SomeButton { get; private set; }

...

public void InitializeDocument()
{
    SomeButton = (Button)Root?.Q("some-button");
}

Steps to Reproduce

  1. Create a new UI Document
  2. Add an element
  3. Set the name in kebab-case
  4. Try to interact with the generated property.

Possible Solution

Might be related to this statement:

SyntaxFactory.Literal(uiProperty.Name)

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.

/// <summary>
/// Gets the UI property name that is used for generating C# properties during the code generation process.
/// </summary>
public string Name { get; }
/// <summary>
/// Gets the UI property name as described in the UXML file.
/// </summary>
public string OriginalName { get; }
public UIProperty(string type, string name)
{
TypeName = type;
Type = UIPropertyTypes.GetUIElementType(type);
OriginalName = name;
Name = name.Contains('-') ? name.ToPascalCase() : OriginalName;
}

EditorWindow support

I think about using this package inside EditorWindow but cannot find a way how I can map UIDocument and EditorWindow.

Editor extensions placed in Editor folder doesn't link properly

🪲 Bug Report

Unity version: 2021.3.16f1
Rosalina version: 2.0.0

Description

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.

Steps to Reproduce

  1. Create an Editor folder in Assets folder.
  2. Create an UIDocument in the Editor folder.
  3. Right click on the UIDocument -> Rosalina -> Generate UI Script
  4. Error on OnCreateGUI() method:

No defining declaration found for implementing declaration of partial method.

Current Behavior

The following C# error appears:

No defining declaration found for implementing declaration of partial method.

Expected Behavior

There should not be any error.

Possible Solution

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.

Generate public readonly properties instead of private fields

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 !
    } 
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.