想让属性显示出来,但是又不想被修改,该怎么做呢?
效果如下:
代码如下:
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class DisableAttribute : PropertyAttribute {
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(DisableAttribute))]
public class DisableDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
EditorGUI.BeginDisabledGroup(true);
EditorGUI.PropertyField(position, property, label);
EditorGUI.EndDisabledGroup();
}
}
#endif
using UnityEngine;
public class DisableExample : MonoBehaviour
{
[Disable] public string hoge = "hoge";
[Disable] public int fuga = 1;
[Disable] public AudioType audioType = AudioType.ACC;
}