In my editor for one of my scripts I am trying to figure out how to remove what is in the red box (Element 0 - Element 14) so basically you would just see the string inputs.
My Editor Script so far :
[CustomEditor(typeof(Change))]
public class Change_Editor : Editor {
public override void OnInspectorGUI(){
// Grab the script.
Change myTarget = target as Change;
// Set the indentLevel to 0 as default (no indent).
EditorGUI.indentLevel = 0;
// Update
serializedObject.Update();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.BeginVertical();
EditorGUILayout.PropertyField(serializedObject.FindProperty("SceneNames"), true);
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
// Apply.
serializedObject.ApplyModifiedProperties();
}
}
EDIT : MotoSV's answer worked and the result is shown below.
To show just the value of each array index you simply have to enumerate through the array and display a field just for the value:
[CustomEditor(typeof(Change))]
public class Change_Editor : Editor
{
public override void OnInspectorGUI()
{
// Grab the script.
Change myTarget = target as Change;
// Set the indentLevel to 0 as default (no indent).
EditorGUI.indentLevel = 0;
// Update
serializedObject.Update();
EditorGUILayout.BeginHorizontal();
EditorGUILayout.BeginVertical();
// >>> THIS PART RENDERS THE ARRAY
SerializedProperty sceneNames = this.serializedObject.FindProperty("SceneNames");
EditorGUILayout.PropertyField(sceneNames.FindPropertyRelative("Array.size"));
for(int i = 0; i < sceneNames.arraySize; i++)
{
EditorGUILayout.PropertyField(sceneNames.GetArrayElementAtIndex(i), GUIContent.none);
}
// >>>
EditorGUILayout.EndVertical();
EditorGUILayout.EndHorizontal();
// Apply.
serializedObject.ApplyModifiedProperties();
}
}
I have not fully tested this, i.e. saved a scene, loaded up and verified all fields are serialized, but the look in the inspector seems to match what you're after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With