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

[MenuItem("PathTool/Set Parent %q")]
static void SetParent()
{

dosomething;

}

 
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 财产属性?搞不懂
也不知道用来做啥的。
 
7.PRC
这个貌似跟NETWORK相关,U3D的NETWORK渣渣,不管了。
 
后续整理

8.Spece
在两个属性间添加一定像素的间隔
 
9.HelpURL
可以添加在线说明,必须在类前面声明,这里点击属性面板中的?则会在浏览器中打开百度网址,注意前面的HTTP://或http://不能省略。

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

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

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

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

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

  3. 转载 JQuery中attr属性和JQuery.data()学习

    转载原地址: http://www.cnblogs.com/yeminglong/p/5405745.html 用html直接data-key来存放,key必须全部小写. <div data-m ...

  4. iOS中文本属性Attributes

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

  5. Unity属性(Attributes)

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

  6. ASP.NET Web API 2 中的属性路由使用(转载)

    转载地址:ASP.NET Web API 2 中的属性路由使用

  7. 【转载】JavaScript中的属性:如何遍历属性

    转载自:http://www.cnblogs.com/ziyunfei/archive/2012/11/03/2752905.html 在JavaScript中,遍历一个对象的属性往往没有在其他语言中 ...

  8. 【转载】 C#使用Select方法快速获取List集合集合中某个属性的所有值集合

    在C#的List集合操作或者数组操作中,有时候我们需要获取到List集合元素中所有的对象的某个属性,然后存放到一个数组集合中,此时就可以使用到List集合以及数组的扩展方法Select方法快速实现获取 ...

  9. 转载:java 中对类中的属性使用set/get方法的意义和用法

    经常看到有朋友提到类似:对类中的属性使用set/get方法的作用?理论的回答当然是封闭性之类的,但是这样对我们有什么作用呢?为什么要这样设计?我直接使用属性名来访问不是更直接,代码更简洁明了吗?下面我 ...

随机推荐

  1. mac 删除自带 ABC 输入法的方法

    首先需要关闭 mac 系统的 SIP ,不然删不掉,不会关的可以查看我的另一篇文章:mac 关闭系统完整性保护 SIP(System Integrity Protection)的方法 . 关闭 SIP ...

  2. [转]ASP.NET母版页中对控件ID的处理

    一.问题提出 由于总体排版和设计的需要,我们往往创建母版页来实现整个网站的统一性,最近我由于统一性的需要,把原来整个项目单独的页面全部套用了母版页.但是出现了一个错误……在我的Blog中记录一下,方便 ...

  3. css百分比问题——`top`、`left`、'translate'的百分比参照谁?

    比如 top.left.transform属性的translate方法,他们的百分比都是相较谁而言的? top.left是基于父元素的: .parent { position: relative; b ...

  4. .net core运行环境搭建 linux + windows

    ---------------------------------------linux------------------------------------------------- 一.添加do ...

  5. SQL 一

    1.所有表都必须在模式中.2.SYS模式不是默认模式3.虽然有概念用户PUBLIC,但它根本没有模式.4.索引有自己的名称空间,存储过程.同义词.表和视图都在同一名称空间里.5.堆是可变长度行的表,这 ...

  6. 『C++』Temp_2018_12_13 函数指针

    #include <iostream> #include <string> using namespace std; class Test{ private: string n ...

  7. 洛谷P3812 【模板】线性基

    题目背景 这是一道模板题. 题目描述 给定n个整数(数字可能重复),求在这些数中选取任意个,使得他们的异或和最大. 输入输出格式 输入格式: 第一行一个数n,表示元素个数 接下来一行n个数 输出格式: ...

  8. exsi6.0远程修改密码

    -------------------------------esxi远程修改root密码--------------------------- 在不接触物理机时,通过启动ssh服务,远程修改密码,具 ...

  9. div盒子水平垂直居中的方法推荐

    父盒子是position:relative 方法一:(宽高确定) div绝对定位水平垂直居中[margin 负间距], 方法二: (宽高确定) div绝对定位水平垂直居中[margin:auto实现绝 ...

  10. react-router-dom实现全局路由登陆拦截

    相比与vue的路由集中式管理,能够很好的进行统一的路由操作,react的路由看起来更乱,想要进行像vue的全局路由管理不是那么得心应手.在我们的项目中,有很多页面是需要登陆权限验证的,最好的方式就是能 ...