How to implement UxmlValueBounds ?

Hi ,

How do you implement UxmlValueBounds ? I tried that and it doesn’t work for me i.e. values are still not being restricted to specified range

UxmlFloatAttributeDescription _ratio = new UxmlFloatAttributeDescription{
    name = "ratio" ,
    defaultValue = 0.3f ,
    restriction = new UxmlValueBounds{ min="0.0" , max="0.9" }
};

I have the same question

The restriction only applies to UXML schema files that are meant to drive autocompletion in external IDEs.
Sadly the framework does nothing else with it at all.

In future Unity version we’re looking at supporting [Range] attribute as part of our larger UXML/C# interop layer revamp.

2 Likes

It would be nice if you used attributes to expose stuff to UI builder rather than all this bloated code of UXMLDescription and UxmlTraits code that we have to keep typing up… just have things like:

[UIBuilderExpose("int",name="some-Name"),Range(0,100)]
public int someName {get;set;}

There is just so much code to write which was much less work in the old system - even though i like the new system not requiring a ton of game objects, its become a lot of work for basic things like a radial fill.

It’s pretty much what we have just added to Unity 2023.2.

https://docs.unity3d.com/2023.2/Documentation/Manual/UIE-custom-tag-name-and-attributes.html

2 Likes