美文网首页Unity编辑器开发分享
想让属性显示出来,但是又不想被修改

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

作者: 循环渐进123456 | 来源:发表于2017-09-25 16:56 被阅读5次

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

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;
}

相关文章

网友评论

    本文标题:想让属性显示出来,但是又不想被修改

    本文链接:https://www.haomeiwen.com/subject/ywjdextx.html