Search Unity

Bug LocalizedString PropertyDrawer foldout-knob disrespects rect-position / bleeds in other area

Discussion in 'Localization Tools' started by Nefahl, Nov 5, 2022.

  1. Nefahl

    Nefahl

    Joined:
    Feb 20, 2017
    Posts:
    71
    The LocalizedString drawer renders in front of the given position, this is quite annoying, since it breaks with other EditorGUI-Elements. See the Color-Field above correctly starting after the toggle-button + 2 pixel offset, while the foldout-knob being rendered inside of the button: upload_2022-11-5_15-56-7.png
    "Fixing" it by adding additional offset, results in the other drawers not being placed neatly after the button:
    upload_2022-11-5_15-55-1.png
    Code is really simple the horizontal position is the default position + width and small offset of the toggle-button
    which is a rect of the size of EditorGUIUtility.singleLineHeight and the height being the height of rendered property provided via the overriden GetPropertyHeight function.
    Can I somehow determine whether or not the property to be rendered respects the given horizontal start-position and if not by how much it bleeds in front of it (best case without having to know the Type of the property-field being rendered)
    Code (CSharp):
    1. EditorGUI.PropertyField(pos, property.FindPropertyRelative("NonReferenceValue""), new GUIContent(""), true);
    Also can we do something about the wasted empty space between label and controls?
    upload_2022-11-5_15-54-41.png
     
  2. Nefahl

    Nefahl

    Joined:
    Feb 20, 2017
    Posts:
    71
    Theres another problem with the width of the drawn property, if it's not the last element placed horizontally, the dropdowns/buttons seem to a) ignore the provided rect for the property-drawer and b) totally get messed up by that:
    upload_2022-11-5_20-52-11.png

    Code (CSharp):
    1. // render with preview
    2. var targetSerializedObject = new SerializedObject(referenceProperty.objectReferenceValue);
    3. var previewValueProperty = targetSerializedObject.FindProperty("_propertyValue");
    4. if (previewValueProperty != null)
    5. {
    6.     // full TargetFieldRect is provided and defines the red marked area plus the area on its right
    7.     var previewRectSplit = fullTargetFieldRect;
    8.     // reduce the rects xMax to aquire half the width of the fill width and be placed on the left side:
    9.     previewRectSplit.xMax = fullTargetFieldRect.xMax - (fullTargetFieldRect.width / 2f);
    10.     // use the same rect for the reference-field (SO) but displace by its own width which equals half width of the total width.
    11.     var referenceRectSplit = previewRectSplit;
    12.     referenceRectSplit.position += new Vector2(previewRectSplit.width, 0f);
    13.            
    14.     // this one does weird stuff if the previewValueProperty is a LocalizedString
    15.     EditorGUI.PropertyField(previewRectSplit, previewValueProperty, new GUIContent(""), true);
    16.                
    17.     EditorGUI.PropertyField(referenceRectSplit, referenceProperty, new GUIContent(""), true);
    18.     targetSerializedObject.ApplyModifiedProperties();
    19.     return;
    20. }
    21. // ... render reference field for full width....
    22.  
    Edit: If I swap rects of preview / reference property they still are placed totally off (outside of the shown area:
    upload_2022-11-5_21-20-0.png
     
    Last edited: Nov 5, 2022
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,292