TylerTemp / SaintsField

A Unity Inspector extension tool focusing on script fields inspector enhancement
MIT License
154 stars 9 forks source link

Visual mess when using SaintsField's ReadOnly #2

Closed MJRamon closed 6 months ago

MJRamon commented 7 months ago

Label and value fields are messed up when using SaintsField's ReadOnly attribute: image

        [ReadOnly, SerializeField] private float _currentForwardSpeedInUnits;
        [ReadOnly, SerializeField] private float _currentSpeedInUnits;
        [ReadOnly, SerializeField] private float _currentSpeedInKmph;
        [ReadOnly, SerializeField] private float _maxSpeedKmph;

Not using ReadOnly attribute: image

        [SerializeField] private float _currentForwardSpeedInUnits;
        [SerializeField] private float _currentSpeedInUnits;
        [SerializeField] private float _currentSpeedInKmph;
        [SerializeField] private float _maxSpeedKmph;
MJRamon commented 7 months ago

Custom solution works fine:

public class ReadOnlyAttribute : PropertyAttribute { }
    [CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
    public class ReadOnlyDrawer : PropertyDrawer {
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
            return EditorGUI.GetPropertyHeight(property, label, true);
        }

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
            var previousGUIState = GUI.enabled;
            GUI.enabled = false;
            EditorGUI.PropertyField(position, property, label, true);
            GUI.enabled = previousGUIState;
        }
    }
TylerTemp commented 7 months ago

Hi, cloud you please provide a reproducible script/project? I at this point can not reproducible this issue:

public class Issue2 : MonoBehaviour
{
    public bool enableVisualDebug;

    [SepTitle("Separate Here", EColor.Black)]
    [ReadOnly, SerializeField] private float _currentForwardSpeedInUnits;
    [ReadOnly, SerializeField] private float _currentSpeedInUnits;
    [ReadOnly, SerializeField] private float _currentSpeedInKmph;
    [ReadOnly, SerializeField] private float _maxSpeedKmph;

    public int throttle;
    public int currentGear;
}

IU Toolkit:

image

IMGUI (Oh there is a bug in IMGUI 😔 but not related to this issue):

image

Unity: 2022.2.0f1


P.S. The readonly and showIf/hideIf indeed need some re-work that I'll do recent days. This is most likely because the EditorGUI.EndDisabledGroup(); failed to execute in pair with EditorGUI.StartDisabledGroup(); in SaintsField. So if you can give more detail it'll be appreciated.

TylerTemp commented 6 months ago

Closed due to can't reproduce + lack of activity.

Please comment on this issue or open another issue if you still face this(or similar) problem.