Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feature Request Use constant variable to remove relying on strings

Discussion in 'UI Toolkit' started by KWaldt, Jan 4, 2021.

  1. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Hi,

    right now, UIToolkits relies heavily on strings. If I have a class and I want to rename it, I need to change the uxml, the uss and the C# code. Is there a way to circumvent that, for example by using a constant variable?
    Code (CSharp):
    1. public class InterfaceVariables
    2. {
    3.     public const string Test = "example-class";
    4. }
    5.  
    6. // Pseudo-Code
    7. <Label class="{InterfaceVariables.Test}" />
    In C#, you can prevent typing string by using consts or nameof. That makes it more comfortable and less error-prone. I'd love it if I could also define my uss class names in a centralised place.

    Best Regards,
    KW
     
    herkip likes this.