Joe*_*eyL 3 c# unity-game-engine
在我的脚本之一的编辑器中,我试图找出如何删除红色框中的内容(元素0-元素14),因此基本上您只会看到字符串输入。
到目前为止,我的编辑器脚本:
[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();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:MotoSV的答案有效,结果如下所示。
要仅显示每个数组索引的值,您只需要在数组中枚举并为该值显示一个字段:
[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();
}
}
Run Code Online (Sandbox Code Playgroud)
我尚未对此进行全面测试,即保存了一个场景,加载并验证了所有字段都已序列化,但是检查器中的外观似乎与您的要求相符。