I dug around for similar questions, but none seem to have been asked, so for the sake of potential Google users with the same issue (especially people newer to Unity/Editor scripting/C#), I believe this question ought to exist.
I was writing a custom property drawer for a class, but for some reason none of the distinct fields were clickable. I was using separate PropertyField
s for float variables, but decided I'd try and use a MultiFloatField
to see if it was going to help. Here's what I did:
var fwd = property.FindPropertyRelative("Forwards").floatValue;
var bwd = property.FindPropertyRelative("Backwards").floatValue;
var left = property.FindPropertyRelative("StrafeLeft").floatValue;
var right = property.FindPropertyRelative("StrafeRight").floatValue;
EditorGUI.MultiFloatField(position, new [] {"F", "B", "L", "R"}.Select(x => new GUIContent(x)).ToArray(), new [] {fwd, bwd, left, right});
Can't live without LINQ. However, when attempting to change the values, they'd immediately reset themselves to whatever their initial value used to be. Given that the MultiFloatField
method returns nothing, how exactly do you extract the edited values out of it?