Unity3d中的属性(Attributes)整理

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

9.下面的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渣渣,不管了。

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-12-26 10:00:39

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

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

附加: float字段检视面板修改:[Range(1,10)] 对属性进行分组:[Header("xxx")] 工具栏中调用方法,类文件需在Editor文件夹中:[MenuIte("")]. [MenuItem("PathTool/Set Parent %q")] static void SetParent() { dosomething: } 转载于: 葱烧烙饼的博客 http://blog.sina.com.cn/aaron888888 At

@property中的属性关键字整理

原子性 nonatomic/atomic 在默认的情况下,由编译器合成的方法会通过锁定机制确保其原子性(atomicity).如果具备nonatomic特质,则不使用同步锁. 读/写权限  readwrite/readonly 内存管理语义 assign "设置方法" 只会针对"纯量类型"(scalar type, CGFloat或NSInteger等)的简单赋值操作 strong "拥有关系" 为这种属性设置新值时,设置方法先保留新值,并释放旧

Unity属性(Attributes)

Unity3d中的属性(Attributes) Attributes属性属于U3D的RunTimeClass,所以加上以下的命名空间是必须的了. using UnityEngine; using System.Collections; 0.Property Attributes变量属性(放在方括号内变量申明前)(常用) 1/ Range(min,max) 如: [SerializeField, Range(0, 5)] int count; 如: [SerializeField, Range(0

Qt中的属性设置(搜集整理)

一.Qt中的属性 属性是指窗口或控件的属性,比如opacity属性表示"透明度",geometry指的是"位置和大小",pos属性代表"位置".qt中的控件有自带的属性,我们也可以自己定义属性. QObject这个类有一个函数setProperty,我们可以通过这个函数定义自己的属性,使用方法很简单,setProperty(const char * name, const QVariant & value),第一个参数是属性的名称,第二个

Unity3D 中的灯光与渲染

最近仔细研究了Unity3D中的灯光以及渲染,有了全新的认识,在这里整理记录下来.博主所使用的是Unity3D 2017.3.1f1这个版本. 一.Unity3D中的灯光 Directional Light:平行光,用来模拟太阳发射的光. Point Light:点光源,用于模拟场景中的灯和其他本地光源. Spot Light:聚光灯,通常用于人造光源,如手电筒,汽车前灯和探照灯. Area Light:区域光,只能用于烘焙中. Reflection Group:反射探针,用于准确反射周围环境.

Unity3D中的Coroutine详解

Unity中的coroutine是通过yield expression;来实现的.官方脚本中到处会看到这样的代码. 疑问: yield是什么? Coroutine是什么? unity的coroutine程序执行流程怎么那么奇怪? unity中的coroutine原理是什么,怎么实现的? 使用unity的coroutine需要注意什么问题? 一.yield的在几种语言中的程序执行特性: Lua中的yield是使得协同函数运行->挂起并且传递参数给resume.resume使得协同函数挂起->运行

Unity3D中的序列化测试

Unity3D中序列化字段常使用[SerializeField],序列化类常采用[System.Serializable],非序列化采用[System.NonSerialized]. 序列化类使用时发现一些区别.测试如下: (1) 将脚本第一次拖拽到场景中后,运行程序.发现,对类进行序列化后,id,name会保持在代码中写的字段值. 如果我们退出运行,对检视面板的值进行修改,再运行,如下图所示.那么会始终运行检视面板中修改的值! 如果我们退出运行,对代码中的值进行修改,再运行,如下图所示.那么发

Unity3D中事件函数的运行顺序

Unity3D中脚本的生命周期是依照预先定义好的事件函数的运行流程来演化的,详细流程例如以下: Editor模式下Reset: 当脚本第一次被挂到GameObject上或用户点击Resetbutton时,Reset被调用初始化脚本属性,最经常使用于在Inspector视图中呈现好的默认值. 载入第一个场景First Scene Load: 场景启动时会对场景中的每一个对象运行一遍例如以下事件函数: Awake:游戏启动之前初始化不论什么变量和游戏状态,仅在脚本生命周期中调用一次.不能做协程,St

Javascript中length属性的总结

Javascript中length属性的总结 一.StringObject中的length     length属性是返回字符串的字符数目. 例如: // 普通字符串 var str = "abcdef"; console.log(str.length); // 6 // 数组 var str1 = new Array(1,2,3,4); console.log(str1.length); // 4 // 数组与字符串 var str2 = str1 + str; // "a