想让属性显示出来,但是又不想被修改

想让属性显示出来,但是又不想被修改,该怎么做呢?
效果如下:

xxx.png

代码如下:

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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,455评论 25 708
  • 刚刚看到一则新闻:海鸥啄食鲸鱼事件。小编我吃惊的一塌糊涂,有道是大魚吃小鱼的自然规律,瞬间被逆袭。 常言道:大鱼吃...
    格小主阅读 282评论 0 0
  • 随着世界经济一体化的趋势不断加强,任何企业都将越来越面临来自内部、外部的各种严峻挑战,企业的愿景和前途,从某种意义...
    Eggyino阅读 173评论 0 0
  • 谁隔重帘乱翻书,清风过处,柳香零叶醉春暮 ---------题记 帘内久伫,不知东风几度,低徊黯数花...
    东吴思王阅读 498评论 2 0
  • 定风波·莫听穿林打叶声 宋代:苏轼译注 三月七日,沙湖道中遇雨。雨具先去,同行皆狼狈,余独不觉,已而遂晴,故作此词...
    行走的背书带阅读 188评论 0 0