Hi,
I want to use CreateProperty attribute to fill the value of a score bar with the value from the scoremanager score property.
In my UxmlElement I added the CreateProperty
[SerializeField, DontCreateProperty]
float m_Score;
[UxmlAttribute, CreateProperty]
public float score
{
get => m_Score;
set
{
m_Score = Mathf.Clamp(value, 0.01f, 100f);
MarkDirtyRepaint(); // Triggers repaint on next frame
}
}
The xml looks like that
<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">
<Style src="project://database/Assets/UI%20Toolkit/USS/scorebar.uss?fileID=7433441132597879392&guid=557099014a6ce4123808da19dd50ea7b&type=3#scorebar" />
<ui:VisualElement style="flex-grow: 1; flex-direction: row;">
<ScoreBar score="56.7" class="red" style="width: 20%; height: 5%;">
<Bindings>
<ui:DataBinding property="score" binding-mode="ToTarget" data-source-type="ScoreManager, Assembly-CSharp" data-source-path="score" />
</Bindings>
</ScoreBar>
<ui:Label tabindex="-1" text="Score:" parse-escape-sequences="true" display-tooltip-when-elided="true" data-source-type="ScoreManager, Assembly-CSharp" data-source-path="score" style="flex-direction: row; width: 20%; color: rgb(255, 255, 255); background-color: rgb(0, 0, 0); height: 10%;" />
<ui:Label tabindex="-1" text="0" parse-escape-sequences="true" display-tooltip-when-elided="true" name="score" data-source-type="ScoreManager, Assembly-CSharp" data-source-path="score" style="width: 10%; height: 10%; background-color: rgb(0, 0, 0); color: rgb(255, 255, 255);">
<Bindings>
<ui:DataBinding property="text" binding-mode="ToTarget" data-source-type="ScoreManager, Assembly-CSharp" data-source-path="score" />
</Bindings>
</ui:Label>
</ui:VisualElement>
</ui:UXML>
In UI Builder I added the binding like that
But when I debug the value at first call of the getter is still not the one from scoremanager but the default (56.7).
And also when the scoremanager score property increases it does not get updated.
So what is wrong?
Thanks!
