Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question EditorGUILayout.PropertyField is not aligned with the default specification in IMGUIContainer.

Discussion in 'UI Toolkit' started by bnm000215, Jul 10, 2023.

  1. bnm000215

    bnm000215

    Joined:
    Sep 6, 2017
    Posts:
    4
    스크린샷 2023-07-10 오후 9.03.07.png

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEditor.UIElements;
    3. using UnityEngine;
    4. using UnityEngine.UIElements;
    5.  
    6. public class ExampleClass : MonoBehaviour
    7. {
    8.     public int Data;
    9. }
    10.  
    11. [CustomEditor(typeof(ExampleClass))]
    12. public class ww : Editor
    13. {
    14.     public override VisualElement CreateInspectorGUI()
    15.     {
    16.         var root = new VisualElement();
    17.         var data = serializedObject.FindProperty("Data");
    18.        
    19.         var UITKPropertyField = new PropertyField(data);
    20.         var IMGUIPropertyField = new IMGUIContainer(() => EditorGUILayout.PropertyField(data));
    21.         root.Add(UITKPropertyField);
    22.         root.Add(IMGUIPropertyField);
    23.  
    24.         return root;
    25.     }
    26. }
    I encountered the same problem as the image I was decorating the InspectorGUI.
    The PropertyField in the UI Toolkit is the same as the fields in other components, but does not match the other components created through IMGUI, such as EditorGUILayout.PropertyFeed.
    What should I do in this case?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    7,846
  3. bnm000215

    bnm000215

    Joined:
    Sep 6, 2017
    Posts:
    4
    OK!
     
    karl_jones likes this.