• 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的脚本中加一个触发事件。就是删除脚本重置脚本button的那个小拉菜单中,具体非常难说清位置,所以我截了个图.

    public class Attributes : MonoBehaviour {
    [ContextMenu("Hello World!")]
    void HelloWorld()
    {
    Debug.Log("Hello World!");
    }
    }
    Unity3d中的属性(Attributes)整理

    图

    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渣渣,无论了。

  • 相关阅读:
    Passion回来了
    VS.NET Addin在Design time获取控件值
    [过时的消息]VS2005 Shipped!
    为asp.net程序添加自定义配置区域
    Visual Studio .NET 2002 Service Pack 1 出来了
    Winform下通过控件名称来获取控件
    new blog, new life
    我的hotmail信箱容量变成2G了!
    first day in microsoft
    在client端通过java script调用Web Service
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/7372262.html
Copyright © 2020-2023  润新知