无法在Unity Inspector上绘制Serializable类

时间:2018-06-17 12:47:55

标签: unity3d drawing editor serializable inspector

这是我的Example类和MonoBehaviour脚本:

using UnityEngine;
using System;

[Serializable]
public class TestSerializableClass
{
    public int a;
    public string b;
}

public class TestScript : MonoBehaviour
{
    public TestSerializableClass field1;
    [HideInInspector] public TestSerializableClass field2;
}

这是MonoBehaviour脚本的编辑器脚本

using UnityEditor;

[CustomEditor(typeof(TestScript))]
public class TestScriptEditor : Editor
{
    SerializedProperty testClass;

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        SerializedProperty testField = serializedObject.FindProperty("field2");
        EditorGUILayout.PropertyField(testField, true);

    }
}

This is how my inspector for TestScript looks.

为什么不像第一个那样绘制“field2”变量?

我可以使用编辑器脚本和属性字段吗?怎么样?

(includeChildre标志为true)

1 个答案:

答案 0 :(得分:0)

从field2中删除HideInInspector属性