- Home /
EditorGUILayout problem with SerializedObject
I would like to customize the menu depending on the context in which there are several variables.
This is my code :
using System; using UnityEditor; using TypeInput = SplinePathMesh.TypeInput; using UnityEngine;
[CustomEditor(typeof(SplinePathMesh))] public class SplinePathMeshEditor : Editor {
SerializedObject m_Object; SerializedProperty m_Property;
void OnEnable() { m_Object = new SerializedObject(target); m_Property = m_Object.GetIterator(); }
public override void OnInspectorGUI() { SplinePathMesh path = (SplinePathMesh)target; EditorGUILayout.BeginVertical(); while (m_Property.NextVisible(true)) { if (path.typeInput == TypeInput.Transform && m_Property.name == "pathVector3") { m_Property.NextVisible(false); } if (path.typeInput == TypeInput.Vector3 && m_Property.name == "pathTransform") { m_Property.NextVisible(false); } //if (m_Property.propertyType != SerializedPropertyType.ObjectReference) { EditorGUILayout.PropertyField(m_Property); //}
}
m_Property.Reset();
EditorGUILayout.EndVertical();
// Apply the property, handle undo
m_Object.ApplyModifiedProperties();
//DrawDefaultInspector();
} }
This function works; But when i click for assign a object i recive this error :
ArgumentException: Getting control 4's position in a group with only 4 controls when doing ExecuteCommand Aborting ArgumentException: Getting control 4's position in a group with only 4 controls when doing repaint Aborting
Answer by Andrea 1 · Apr 06, 2011 at 03:55 PM
I find the solution myself :
using System;
using UnityEditor;
using TypeInput = SplinePathMesh.TypeInput;
using UnityEngine;
[CustomEditor(typeof(SplinePathMesh))]
public class SplinePathMeshEditor : Editor {
SerializedObject m_Object;
SerializedProperty m_Property;
void OnEnable() {
m_Object = new SerializedObject(target);
}
public override void OnInspectorGUI() {
m_Property = m_Object.GetIterator();
SplinePathMesh path = (SplinePathMesh)target;
EditorGUILayout.BeginVertical();
while (m_Property.NextVisible(true)) {
if (path.typeInput == TypeInput.Transform && m_Property.name == "pathVector3") {
m_Property.NextVisible(false);
}
if (path.typeInput == TypeInput.Vector3 && m_Property.name == "pathTransform") {
m_Property.NextVisible(false);
}
EditorGUILayout.PropertyField(m_Property);
}
m_Property.Reset();
EditorGUILayout.EndVertical();
// Apply the property, handle undo
m_Object.ApplyModifiedProperties();
//DrawDefaultInspector();
}
}
why do you think you need to create SerializedObject Object when you have reference of it as serializedObject ?
Your answer