Search Unity

Check button click area overlaps its neighbors - is it a bug?

Discussion in 'Scripting' started by Veetha, Feb 17, 2019.

  1. Veetha

    Veetha

    Joined:
    Jun 27, 2017
    Posts:
    6
    Hello,
    the gif shows part of UI of my IK script. Each line bellow "anchor objects" title is defined by class "AnchorDrawer". First column of check boxes actually simulates radio buttons, because only one anchor can by active for editing in the same time. The second column determine whether the anchor is used. As you can see on the gif, onclick area of check boxes is somehow misplaced. Is it a unity bug or is it my mistake? Is there a workaround or better way to achieve this layout?
    Thank you for your advice.

    Version 2018.3.0f2

    ikscript bug.gif

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. [System.Serializable]
    7. public class AnchorInput
    8. {
    9.     public bool edit = false;
    10.     public bool enabled = true;
    11.     public Transform anchor = null;
    12.  
    13.     private static List<AnchorInput> list = new List<AnchorInput>();
    14.  
    15.     AnchorInput()
    16.     {
    17.         list.Add(this);
    18.     }
    19.  
    20.     public static List<AnchorInput> getInstances()
    21.     {
    22.         return new List<AnchorInput>(list);
    23.     }
    24. }
    25.  
    26. [CustomPropertyDrawer(typeof(AnchorInput))]
    27. class AnchorDrawer : PropertyDrawer
    28. {
    29.  
    30.     // Draw the property inside the given rect
    31.     public override void OnGUI(Rect originalPosition, SerializedProperty property, GUIContent label)
    32.     {
    33.         // Using BeginProperty / EndProperty on the parent property means that
    34.         // prefab override logic works on the entire property.      
    35.         EditorGUI.BeginProperty(originalPosition, label, property);
    36.  
    37.         // Draw label
    38.         Rect position = EditorGUI.PrefixLabel(originalPosition, GUIUtility.GetControlID(FocusType.Passive), label);
    39.        
    40.         // Calculate rects
    41.         Rect editRadioButton = new Rect(position.x, position.y, position.x + 20, position.height);
    42.         Rect enabledCheckButton = new Rect(position.x + 30, position.y, position.x + 50, position.height);
    43.         Rect anchorInput = new Rect(position.x + 50, position.y, originalPosition.width - position.x-16-20, position.height);
    44.  
    45.         // Draw fields - passs GUIContent.none to each so they are drawn without labels
    46.         EditorGUI.PropertyField(editRadioButton, property.FindPropertyRelative("edit"), GUIContent.none);
    47.         EditorGUI.PropertyField(enabledCheckButton, property.FindPropertyRelative("enabled"), GUIContent.none);
    48.         EditorGUI.PropertyField(anchorInput, property.FindPropertyRelative("anchor"), GUIContent.none);
    49.  
    50.         EditorGUI.EndProperty();
    51.     }
    52. }