#Properties not drawn in right place

1 messages · Page 1 of 1 (latest)

zinc pivot
#

Im practicing some GUI editing. im trying some property drawing but for some reason the properties get drawn outside of the box instead of inside?

#

There are 4 scripts which coudl affect this prblem

#

The component script
`public enum UnitType {Kg, Lbs}

[AddComponentMenu("AeroPyhsics/Airplane Body")]
public class AeroBody : MonoBehaviour
{
[SerializeField] private Rigidbody _rb;
[SerializeField] private float _weight;
[SerializeField] private UnitType _unit;
[SerializeField] private AeroSurface[] _aeroSurfaces;
[SerializeField] private AeroEngine[] _aeroEngines;
}`

#

The component editor

`[CustomEditor(typeof(AeroBody))]
public class AeroBodyEditor : Editor
{
private SerializedProperty _rb;
private SerializedProperty _weight;
private SerializedProperty _unit;
private SerializedProperty _aeroSurfaces;
private SerializedProperty _aeroEngines;

private void OnEnable()
{
    _rb = serializedObject.FindProperty("_rb");
    _weight = serializedObject.FindProperty("_weight");
    _unit = serializedObject.FindProperty("_unit");
    _aeroSurfaces = serializedObject.FindProperty("_aeroSurfaces");
    _aeroEngines = serializedObject.FindProperty("_aeroEngines");
}

public override void OnInspectorGUI()
{
    serializedObject.UpdateIfRequiredOrScript();
    EditorGUILayout.PropertyField(_rb, new GUIContent("Rigid Body"));
    if (_rb.objectReferenceValue == null)
    {
        EditorGUILayout.HelpBox("This component is depended on a RigidBody", MessageType.Error);
    }
    //begin horizontal
    EditorGUILayout.BeginHorizontal();
    EditorGUILayout.PropertyField(_weight, new GUIContent("Weight"));
    EditorGUIUtility.labelWidth = 30;
    EditorGUILayout.PropertyField(_unit, new GUIContent(""));
    EditorGUILayout.EndHorizontal();
    //end horizontal        
    EditorGUILayout.PropertyField(_aeroSurfaces, new GUIContent("Aero Surfaces:"));
    if (_aeroSurfaces.arraySize == 0)
    {
        EditorGUILayout.HelpBox("There aren't any Aero Surfaces assigned", MessageType.Warning);
    }
    EditorGUILayout.PropertyField(_aeroEngines, new GUIContent("Aero Engines:"));
    if (_aeroEngines.arraySize == 0)
    {
        EditorGUILayout.HelpBox("There aren't any Aero Engines assigned", MessageType.Warning);
    }

    serializedObject.ApplyModifiedProperties();
}

}`

#

The aeroEngine class

`public enum EngineType {Propeller, Jet}

[System.Serializable]
public class AeroEngine
{
[SerializeField] private EngineType _engineType = EngineType.Propeller;
[SerializeField] private Vector3 _position = Vector3.zero;
[SerializeField] private Vector3 _direction = Vector3.forward;
[SerializeField] private float _thrust = 0;
[SerializeField] private int _throttle = 0;
[SerializeField] private float _efficiency = 0;
[SerializeField] private float _impulse = 0;
[SerializeField] private float _rps = 0;
[SerializeField] private float _diameter = 0;
[SerializeField] private float _thrustCo = 0;
[SerializeField] private float _inletWidth = 1;
[SerializeField] private float _inletHeight = 1;
}`