#I m trying to update the value of a

1 messages · Page 1 of 1 (latest)

latent glen
#

@pallid prism can I see the entire script?

pallid prism
#

@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();
        }
    }
latent glen
#

are you sure you're not setting the property to a value in a start or awake method on the object?

#

@pallid prism

pallid prism
latent glen
pallid prism
latent glen
#

simple enough lol

#

I wonder if it has to do with the fact that it's a record. Why record and not struct btw?

pallid prism
latent glen
#

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.

pallid prism
#

Ye just came to the same conclusion

#

I'll have to convert my property first

latent glen
#

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.

pallid prism
#

Thanks for the help

latent glen
#

that'll be easy enough! ofc.

#

probably just int divide by 60 to get the minutes and mod by 60 to get the seconds btw.

#

@pallid prism