我在从 UnityEngine.Editor 派生的 CustomEditor 类中有 GameObject 数组字段。我需要能够显示(绘制)并让用户能够修改该数组。
就像 Unity 的 Inspector 如何为从 ScriptableObject 派生的对象的 Serializable 字段执行此操作一样。例如。在检查器中显示 Material 数组:
最佳答案
关于 SerializedObject 引用你的编辑器对象,然后找到任何需要的属性,绘制它,并应用修改:
public class MyEditorWindow : EditorWindow
{
[MenuItem("Window/My Editor Window")]
public static void ShowWindow()
{
GetWindow<MyEditorWindow>();
}
public string[] Strings = { "Larry", "Curly", "Moe" };
void OnGUI()
{
// "target" can be any class derrived from ScriptableObject
// (could be EditorWindow, MonoBehaviour, etc)
ScriptableObject target = this;
SerializedObject so = new SerializedObject(target);
SerializedProperty stringsProperty = so.FindProperty("Strings");
EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
so.ApplyModifiedProperties(); // Remember to apply modified properties
}
}
原始答案 here 。
关于unity3d - 如何在编辑器窗口中显示和修改数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47753367/