#I m trying to update the value of a
1 messages · Page 1 of 1 (latest)
@latent glen sure
[CustomPropertyDrawer(typeof(TimeData))]
public class TimeDataUIE : PropertyDrawer
{
int _minutes;
int _seconds;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
// Using BeginProperty / EndProperty on the parent property means that
// prefab override logic works on the entire property.
EditorGUI.BeginProperty(position, label, property);
// Draw label
label.text += " (minutes:seconds)";
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
// Don't make child fields be indented
var indent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
// Calculate rects
var amountRect = new Rect(position.x, position.y, 30, position.height);
var colonRect = new Rect(position.x + 31, position.y, 6, position.height);
var unitRect = new Rect(position.x + 39, position.y, 30, position.height);
var fieldStyle = new GUIStyle(GUI.skin.textField)
{
alignment = TextAnchor.MiddleCenter
};
_minutes = EditorGUI.IntField(amountRect, _minutes, fieldStyle);
GUI.Label(colonRect, ":");
_seconds = EditorGUI.IntField(unitRect, _seconds, fieldStyle);
_minutes = Mathf.Clamp(_minutes, 0, 60);
_seconds = Mathf.Clamp(_seconds, 0, 60);
property.FindPropertyRelative("value").floatValue = _minutes * 60 + _seconds;
// Set indent back to what it was
EditorGUI.indentLevel = indent;
EditorGUI.EndProperty();
}
}
are you sure you're not setting the property to a value in a start or awake method on the object?
@pallid prism
Yup, pretty sure. Just tested it on an empty monobeh with single TimeData field present
can you send the TimeData class? I want to put both of these in a unity project to debug it. It's easier for me than just reading it, especially with editor scripts.
[Serializable]
public record TimeData
{
public float value;
}
simple enough lol
I wonder if it has to do with the fact that it's a record. Why record and not struct btw?
Tried using a struct, still the same behaviour.
I'm just using records cause you can declare them as record foo (args)Typescript genes
ah
so I'm like 90% sure it's because _minutes and _seconds get set to 0 every time the property drawer is redrawn or reselected because obviously their default value is 0 so when a new intance of TimeDataUIE is created they're set to 0 and then value is set to _minutes * 60 + _seconds because the intFields are set to what _minutes and _seconds are, which is now 0.
so I'd try converting the value to minutes and seconds then seperating them into the seperate int fields then combining them back into one value.
Thanks for the help