[HideInInspector] [SerializeField]
[ReadOnly] [readonly]原文链接:http://blog.csdn.net/cartzhang/article/details/53888588
1.引用 using UnityEditor,然后加上下面的代码。
using System.Collections; using System.Collections.Generic; using UnityEngine; #if using UnityEditor; #endif public class ReadOnlyAttribute : PropertyAttribute { } [CustomPropertyDrawer(typeof(ReadOnlyAttribute))] public class ReadOnlyDrawer : PropertyDrawer { public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { return EditorGUI.GetPropertyHeight(property, label, true); } public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { GUI.enabled = false; EditorGUI.PropertyField(position, property, label, true); GUI.enabled = true; } }2.写字段的时候加上[ReadOnly]
[ReadOnly] public GameObject C;Ok,都是些小东西,有备无患吧。