Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了。其它倒没什么需要注意的。本文将所有运行属性过一遍罢了。
using UnityEngine;
using System.Collections;
 
1.AddComponentMenu 添加组件菜单
这函数只是起方便用,原本的脚本(组建)都会在“Component/Script”菜单下,在类之前声明一下这个,它便可以出现在"Componet"菜单下的任何位置。说明指的是要重启U3D才能显示,不过测试貌似直接可以显示。
 
[AddComponentMenu("MyPhysic/PhysicType")]
public class PhysicType: MonoBehaviour
{
}
 
2.ContextMenu 上下文菜单
这个译名我觉得很不自然,其实上下文算是啥东西……这个函数是在Inspector的脚本中加一个触发事件,就是删除脚本重置脚本按钮的那个小拉菜单中,具体很难说清位置,所以我截了个图。
public class Attributes : MonoBehaviour {
    [ContextMenu("Hello World!")]
    void HelloWorld()    
    {
        Debug.Log("Hello World!");
    }   
}

3.ExecuteInEditMode 在Editor模式下运行
跟名字一样,在编辑器中运行。不过有三种函数的调用方式。
a- "Update()" is only called when something in the scene changed.
b- "OnGUI()" is called when the Game View recieves an Event.
c- "OnRenderObject()" and the other rendering callback functions are called on every repaint of the Scene View or Game View.
 
[ExecuteInEditMode]
public class ExecuteInEditModeTest: MonoBehaviour
{
    private Vector3 vec_Rotation = new Vector3(0.0f, 0.5f, 0.0f);
    //Rotate all the time
    void OnRenderObject()
    {
        transform.Rotate(vec_Rotation);
    }
}
 
4.HideInInspector 在检视面板中隐藏
public class HideInspectorTest : MonoBehaviour 
{
    
    [HideInInspector]
 
    public Transform m_Target;
    void Start()
    {
        m_Target = GameObject.Find("test").transform;
    }
 
}
 
5.RequireComponent 必须要有相应的组建
加入一个组建之前必须存在另一个相应的组建,若没有则自动创建。这个在项目中非常有必要用到,尤其是项目人员比较多的时候(大于三四个)。
[RequireComponent (typeof (Rigidbody))]
public class RequireComponentTest : MonoBehaviour {
    void FixedUpdate()  {
        rigidbody.AddForce(Vector3.up);
    }
}
 
6.NonSerialized 不被序列化
不被序列化该变量,且不显示在检视面板中。
public class Test {
    [System.NonSerialized]
    public int i_Helloword = 5;
}
 
7.Serializable 可序列化
这个属性可以让子类(继承类)的变量属性显示在检视面板中,也能序列化它。(JS的话完全不需要这个属性。)
//SerializableTest.cs
[System.Serializable]
public class SerializableTest
{
    public int p = 5;
    public Color c = Color.white;
}
 
//SerializableTest2.cs
public class SerializableTest2 : MonoBehaviour
{
    public SerializableTest test;
 
}
 

8.SerializeField 序列化域(强制序列化)
这里写得比较清楚,可以将私有变量序列化,将U3D的内建变量序列化等。
http://game.ceeger.com/Script/Attributes/SerializeField.html
 
下面的ATTRIBUTE属性估计是没什么人用的了,我也没怎么用过。
 
1.ImageEffectOpaque 不透明图像效果优先
Any Image Effect with this attribute will be rendered after opaque geometry but before transparent geometry.
This allows for effects which extensively use the depth buffer (SSAO ect) to only affect opaque pixels. This Attribute can be used to reduce the amount of visual artifacts in a scene with post processing.
没用过这玩意,不过应该很少用得到,优化加速渲染。
 
2.ImageEffectTransformsToLDR 
也没用过这玩意,LDR应该是某种加载方式。高动态光照渲染(High-Dynamic Range,简称HDR)。
When using HDR rendering it can sometime be desirable to switch to LDR rendering during ImageEffect rendering.
Using this Attribute on an image effect will cause the destination buffer to be an LDR buffer, and switch the rest of the Image Effect pipeline into LDR mode. It is the responsibility of the Image Effect that this Attribute is associated to ensure that the output is in the LDR range.
 
3.NotConvertedAttribute 不转换属性
我觉得这个应该是没有人用的……打包资源的时候,不将成员或类型转换到相应平台,不是很理解这是干嘛的。
Instructs the build pipeline not to convert a type or member to the target platform.
 
 
4.NotFlashValidatedAttribute 不允许转换到FLASH平台
又是个没人用的东西吧?
Instructs the build pipeline not to try and validate a type or member for the flash platform.
 
5.NotRenamedAttribute 不允许属性更名
……
 
6.PropertyAttribute 财产属性?搞不懂

Unity3d中的属性(Attributes)整理的更多相关文章

  1. (转载)Unity3d中的属性(Attributes)整理

    附加: float字段检视面板修改:[Range(1,10)] 对属性进行分组:[Header("xxx")] 工具栏中调用方法,类文件需在Editor文件夹中:[MenuIte( ...

  2. (转)Unity3d中的属性(Attributes)整理

    Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了.其它倒没什么需要注意的.本文将所有运行属性过一遍罢了. using UnityEngine; using ...

  3. iOS中文本属性Attributes

    NSFontAttributeName //设置字体大小 NSParagraphStyleAttributeName //设置段落格式 NSForegroundColorAttributeName / ...

  4. Unity属性(Attributes)

    Unity3d中的属性(Attributes) Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了. using UnityEngine; using Sy ...

  5. php面向对象基础知识整理之类中的属性和方法的使用

    <?php /** * class Index * 类包含什么 * 1.创建类 * 2.类的属性和类中方法 * 3.类中访问修饰符 * 4.类的封装.继承.多态 */ // 创建类,创建的类名是 ...

  6. 【Unity3d游戏开发】Unity3D中的3D数学基础---向量

    向量是2D.3D数学研究的标准工具,在3D游戏中向量是基础.因此掌握好向量的一些基本概念以及属性和常用运算方法就显得尤为重要.在本篇博客中,马三就来和大家一起回顾和学习一下Unity3D中那些常用的3 ...

  7. Unity3D中可中途释放的单例

    Unity3D中可中途释放的单例 使用静态类,静态变量的坏处是从程序加载后就一直占用内存,想要释放比较麻烦,可是之前使用的单例,没有提供释放的方法,那是不是也同静态的一样直到程序结束菜释放?那单例的好 ...

  8. 给iOS开发新手送点福利,简述文本属性Attributes的用法

    给iOS开发新手送点福利,简述文本属性Attributes的用法   文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSF ...

  9. unity3d中 刚体(Rigidbody) 碰撞体(Collider) 触发器(Is Trigger)

      刚体(Rigidbody)的官方(摘自Unity3d的官方指导书<Unity4.x从入门到精通>)解释如下: Rigidbody(刚体)组件可使游戏对象在物理系统的控制下来运动,刚体可 ...

随机推荐

  1. [OpenCV-Python] OpenCV 中的图像处理 部分 IV (三)

    部分 IVOpenCV 中的图像处理 OpenCV-Python 中文教程(搬运)目录 19 Canny 边缘检测 目标 • 了解 Canny 边缘检测的概念 • 学习函数 cv2.Canny() 1 ...

  2. Ucinet6 + Netdraw 根据excel文件绘制网络拓扑图

    条件: 具备Ucinet6 和 Netdraw 两款软件的Windows excel文件格式(.xlsx  .xls  .csv):必须是数字,如果现有的文件不是数字,可以采用某种编码的方式将其映射成 ...

  3. 015.Linux系统删根数据恢复

    重要声明: 本文档所有思路来自于誉天教育,由本人(木二)在实验环境验证通过: 您应当通过誉天邹老师或本人提供的其他授权通道下载.获取本文档,且仅能用于自身的合法合规的业务活动: 本文档的内容仅供学习交 ...

  4. lintcode 单词接龙II

    题意 给出两个单词(start和end)和一个字典,找出所有从start到end的最短转换序列 比如: 1.每次只能改变一个字母. 2.变换过程中的中间单词必须在字典中出现. 注意事项 所有单词具有相 ...

  5. sass和less

    一.相同点 sass和less具有变量.作用域.混合.嵌套.继承.运算符.颜色函数.导入和注释等基本特性,而且以“变量”.“混合”.“嵌套”.“继承”和“颜色函数”为五大基本特性. sass和less ...

  6. Some Formulas.

    目录 计数问题 在一个有\(n\)个点的完全图(complete graph)中有多少棵生成树 排列组合 1. 当 \(C_n^m\) 为奇数时,\((n\&m)==m\) 2. \[\sum ...

  7. JVM笔记(一)数字在JVM中的表示

    数字在JVM中的表示 一.整数在JVM中的表示 1.在Java虚拟机中,整数有四种表示: byte:8位        short:16位     int:32位     long:64位 2.原码. ...

  8. 2016年3月17日Android学习笔记

    1.Java.io.ByteArrayOutputStream.writeTo()方法实例 java.io.ByteArrayOutputStream.writeTo(OutputStream out ...

  9. 一个servlet处理多个请求或者叫方法

    http://blog.csdn.net/qq_25201665/article/details/52037607

  10. 喵哈哈村的魔法考试 Round #15 (Div.2) 题解

    哗啦啦村的奇迹果实(一) 题解:显然答案就是最大值减去最小值. #include<bits/stdc++.h> using namespace std; const int maxn = ...