unity3d - 如何在编辑器窗口中显示和修改数组?

标签 unity3d window editor

我在从 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/

相关文章:

c# - 如何修复面向玩家的翻转世界空间 UI?

java - 获取 Eclipse 编辑器的当前源代码?

firefox-addon - 如何从 Firefox 插件打开外部应用程序? (例如 : default text editor)

c# - 统一: Null while making new class instance

image - 在 Unity 中无法更改黑色图像的颜色

c# - Unity,实例化一个预制件,要求它有一个特定的脚本

linux - 如何远程调试

python - 将 openCV 窗口置于前面并关注焦点 macOS

iphone - 在钛合金的多个窗口之间导航

c# - 是否有任何带有 C# 代码完成插件的 emacs 或 vim 编辑器?