在扩展Unity的时候,往往会用到一些属性,这里将常用的列一下。

1、属性只读;

#if UNITY_EDITOR
using UnityEditor;
#endif using UnityEngine; public 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 string PLUGIN = "";

2、私有变量在 Inspector 显示出来  [SerializeField]

[ReadOnly]
[SerializeField]
private string ABC = "abc";

效果如下:

3、为属性添加头部说明 [HeaderAttribute]

using UnityEngine;
using System.Collections; public class ExampleClass : MonoBehaviour {
[Header("Health Settings")]
public int health = 0;
public int maxHealth = 100;
[Header("Shield Settings")]
public int shield = 0;
public int maxShield = 0;
}

4、隐藏属性 [HideInInspector]

using UnityEngine;
using System.Collections; public class ExampleClass : MonoBehaviour {
[HideInInspector]
public int p = 5;
}

其它还有诸如 HelpURL 等,详情可参考 官方帮忙文档 https://docs.unity3d.com/ScriptReference/HeaderAttribute.html

Unity Inspector面板常用的属性的更多相关文章

  1. Inspector a ProgressBar(定制属性面板)

    一.定制进度条 这篇文章主要学习如何在Unity的Inspector中使用ProgressBar 普通属性面板预览 通常我们的属性面板如下 定制属性面板预览 而通过扩展成ProcessBar后 二.内 ...

  2. 使用反射功能在Unity运行状态通过Inspector面板修改字段和调用方法

    使用反射功能在Unity运行状态通过Inspector面板修改字段和调用方法 效果展示 一个很简单的组件脚本 运行状态在Inspector面板可以随便修改字段和调用方法 方法调用日志 设计由来 最近在 ...

  3. Unity 自定义Inspector面板时的数据持久化问题

    自定义Inspector面板的步骤: Unity内创建自定义的Inspector需要在Asset的任意文件夹下创建一个名字是Editor的文件夹,随后这个文件夹内的cs文件就会被放在vstu生成的Ed ...

  4. Unity编辑器环境在Inspector面板中显示变量

    Serialize功能Unity3D 中提供了非常方便的功能可以帮助用户将 成员变量 在Inspector中显示,并且定义Serialize关系. 简单的说,在没有自定义Inspector的情况下所有 ...

  5. 让Unity的Inspector面板支持字符限制(restrict)功能

    今天在优化红点组件,笔者打算将红点id由10进制改为16进制处理,就打算将红点id字段由uint类型改成string类型,用于填写16进制的字符(因为在Inspector面板里,uint/int类型字 ...

  6. Unity编辑器重写Inspector面板,面板中编辑的数据不触发场景发生变化的问题。

    今天开始协助主程一起制作新框架.主程让我写关于新版UI框架注册UI预制体用的快捷编辑器. 现学现写,总算完成了. 可以直接把选中的预制体添加到UIController的数组中,期间涉及到改变大小.所以 ...

  7. Unity 3D的常用快捷键

    Unity中的常用快捷键 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) 1 Windows系统Unity3 ...

  8. Unity3d Inspector面板实现set/get访问器

    简单说一下属性和字段的区别:字段就是成员变量,而属性确实提供给外部访问内部成员变量的接口.之所以会有属性的出现,就是为了避免外部对类的成员的直接访问,通俗的说就是OOP中的封装思想. using Un ...

  9. Unity检视面板的继承方法研究 (二)

    之前做了普通对象的可继承的检视面板类, 现在想要实现对Unity自带的检视面板的继承的话, 要怎样写呢? 万变不离其宗,  仍然是围绕UnityEditor.Editor.CreateEditor 这 ...

随机推荐

  1. ionic2/cordova自定义插件集成aar包

    一.准备自定义插件 1. 准备:安装plugman npm install -g plugman 2. 新建组件 plugman create --name MyPlugin --plugin_id ...

  2. Nessus忘记密码的解决

    进入到Nessus安装目录下

  3. day8.登陆注册简单实现

    username = input('请输入注册的用户名:') password = input('请输入注册名的密码:') with open('list_of_info',mode='w',enco ...

  4. seafile增加邮件服务功能

    这个很简单哈,直接上配置.此处我用的163邮箱 vim /opt/seafile/conf/seahub_settings.py ### 163邮箱配置测试 ### EMAIL_USE_SSL = F ...

  5. 008 pandas介绍

    一:介绍 1.官网 http://pandas.pydata.org/ 2.说明 Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了 ...

  6. day40 mycql 视图,触发器,存储过程,函数

    视图,触发器,存储过程,自定义函数 -- 回顾 1.mysql 约束 1.非空 not null 2. 主键约束 primary key 3. 唯一约束 unique 4. 外键约束 foreign ...

  7. TF:TF分类问题之MNIST手写50000数据集实现87.4%准确率识别:SGD法+softmax法+cross_entropy法—Jason niu

    import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data # number 1 to 10 ...

  8. Linux学习之源码包安装与脚本安装(十八)

    Linux学习之源码包安装与脚本安装 目录 源码包与RPM包的区别 源码包安装 脚本安装 源码包与RPM包的区别 1.区别 安装之前的区别:概念上的区别 安装之后的区别:安装位置不同 源码包: 开源的 ...

  9. mumu模拟器设置代理/打开网络连接(windows)

    adb_server.exe devicesadb_server.exe connect 127.0.0.1:7555adb_server.exe shell am start -a android. ...

  10. scrapy 安装

    windows 1.wheelpip install wheel2.lxmlhttp://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml3.PyOpensslhttp ...