Untiy 只读属性实现
来源:互联网 发布:淘宝财富值怎么刷的 编辑:程序博客网 时间:2024/05/22 17:25
本文章由cartzhang编写,转载请注明出处。 所有权利保留。
文章链接:http://blog.csdn.net/cartzhang/article/details/53888588
作者:cartzhang
想在Untiy 中,在检视板上看到,但是有不希望别人在检视板上改动。
这时候就会有人说,怎么不使用检视板的debug模式呢?
我不想动手点击,就希望看到,灰色起来方便看属性值的变化。
下面的代码就十分有用了。
using UnityEngine;#if UNITY_EDITORusing UnityEditor;#endifpublic class ReadOnlyAttribute : PropertyAttribute{}#if UNITY_EDITOR[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; }}#endif
只需要代码写的时候
[ReadOnly] public int numberTest = 100;
这样就可以了。
—————————THE———–END———
若有问题,请随时来联系!!
非常感谢!!
0 0
- Untiy 只读属性实现
- Untiy 灯光属性介绍
- PHP实现设置文本框的只读属性
- 用反射实现PropertyGrid中的属性动态实现只读、可见
- Untiy
- .Net/C# 实现真正的只读属性 (ReadOnly Property)
- 怎样用客户端JScript实现区域的只读属性
- html+js实现文本框背景及只读属性修改
- 用JS实现input输入框里的只读属性
- WCF - 只读属性
- CEdit 字体大小 只读属性
- 关于只读属性
- combobox只读属性
- linux文件只读属性
- javascript对象只读属性
- 初始化一个只读属性
- 只读属性的赋值
- select 设置只读属性
- Angular学习之过滤器<filter>
- c#如何定义全局变量list
- 161226学习日记
- AbstractListView源码分析6
- java日常笔记2016-12-26
- Untiy 只读属性实现
- 如何给EmapDataTable添加统计行
- node.js path模块属性方法
- Android 6.0以上 动态权限申请
- Android中ListView的使用(一)
- 蓝桥带分数(全排列)
- Html5 Websocket while死循环的问题
- 作为程序员,也许其他的也许可以不看,但是这些你值得一看(细节决定成败)
- spring bean 的理解