Greetings. I’m displaying an array of elements with custom PropertyDrawers. But whenever I modify a property in a drawer the last element in the array gets modified instead. It seems only the last array’s element gets referenced. I tried to do it with a ListView and the result was the same. I even tried to draw the list by myself in a loop and the problem still persist.
forsakenvapidibis
I don’t know if this is the normal behaviour or I’m doing something wrong, but my code is fair simple
public class AnimatedPropertyDrawer : PropertyDrawer
{
private const string TREE_NAME = "AnimatedPropertyDrawer.uxml";
private const string STYLE_NAME = "AnimatedPropertyDrawer.uss";
private VisualElement _propertiesContainer;
public override VisualElement CreatePropertyGUI(SerializedProperty property)
{
string treePath = this.GetAssetPath() + TREE_NAME;
string stylePath = this.GetAssetPath() + STYLE_NAME;
VisualElement container = ROJOEditor.LoadAssetTree(treePath);
container.LoadStyleSheet(stylePath);
container.AddToClassList("animation-field");
Toggle enabledToggle = container.Q<Toggle>("enabledToggle");
enabledToggle.BindProperty(property.FindPropertyRelative("Enabled"));
enabledToggle.RegisterValueChangedCallback(OnEnabledToggle);
_propertiesContainer = container.Q<VisualElement>("propertiesContainer");
_propertiesContainer.Add(new PropertyField(property.FindPropertyRelative("properties")));
SetEnabled(enabledToggle.value);
return container;
}
private void OnEnabledToggle(ChangeEvent<bool> evt)
{
bool value = evt.newValue;
SetEnabled(value);
}
private void SetEnabled(bool value)
{
_propertiesContainer.EnableInClassList("hidden", !value);
}
}