Reputation: 1305
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.
Upvotes: 4
Views: 7630
Reputation: 2368
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.
Upvotes: 7