登录
  • 欢迎访问 Sharezer Blog

UnityEngine Attributes

Api sharezer 2394次浏览 已收录 0个评论

AddComponentMenu
添加组件菜单(可以在UnityEditor的Component的Menu中增加自定义的项目)
[AddComponentMenu("Transform/Follow Transform")]
AssemblyIsEditorAssembly
汇编级属性,使用该属性的Class会被认为是EditorClass
ColorUsageAttribute
用于配置颜色和颜色选择
ContextMenu
可以在Inspector的ContextMenu中增加选项
[ContextMenu ("Do Something")]
ContextMenuItemAttribute
可以在Inspector上面对变量追加一个右键菜单,并执行指定的函数
public class ExampleClass : MonoBehaviour {
  [ContextMenuItem("Reset", "ResetBiography")]
  [Multiline(8)]
  public string playerBiography = "";
  void ResetBiography() {
  playerBiography = "";
  }
}
CreateAssetMenuAttribute

DelayedAttribute
延迟变量(直到用户输入Enter或失去焦点才生效)
DisallowMultipleComponent
对一个MonoBehaviour的子类使用这个属性,那么在同一个GameObject上面,最多只能添加一个该Class的实例
ExecuteInEditMode
默认状态下,MonoBehavior中的Start,Update,OnGUI等方法,需要在Play的状态下才会被执行
这个属性让Class在Editor模式(非Play模式)下也能执行,但是与Play模式也有一些区别
Update方法只在Scene编辑器中有物体产生变化时,才会被调用
OnGUI方法只在GameView接收到事件时,才会被调用
OnRenderObject和渲染回调在SceneView或GameView重画才会被调用
GUITargetAttribute
可以控制显示的OnGUI
using UnityEngine;
public class ExampleClass : MonoBehaviour {
  // Label will appear on display 0 and 1 only
  [GUITarget(0, 1)]
  void OnGUI()
  {
  GUI.Label(new Rect(10, 10, 300, 100), "Visible on TV and Wii U GamePad only");
  }
HeaderAttribute
在Inspector中变量的上面增加Header
HelpURLAttribute
为一个类提供自定义文档的地址
HideInInspector
让public的变量在Inspector上隐藏
ImageEffectOpaque
在OnRenderImage上使用,可以让渲染顺序在非透明物体之后,透明物体之前
ImageEffectTransformsToLDR
渲染从从HDR变为LDR 具体使用方法不明
MultilineAttribute
在string类型上使用,可以在Editor上输入多行文字
PropertyAttribute
从基类派生自定义属性属性。使用这个脚本创建自定义属性变量(See Also: PropertyDrawer class.)
RangeAttribute
在int或者float类型上使用,限制输入值的范围
RequireComponent
在Class上使用,添加对另一个Component的依赖。
当该Class被添加到一个GameObject上的时候,如果这个GameObject不含有依赖的Component,会自动添加该Component。
且该Componet不可被移除。
RPC
在方法上添加该属性,可以网络通信中对该方法进行RPC调用
RuntimeInitializeOnLoadMethodAttribute
在游戏启动时,会自动调用添加了该属性的方法
[RuntimeInitializeOnLoadMethod]
  static void OnRuntimeMethodLoad ()
  {
  Debug.Log("After scene is loaded and game is running");
  }
SelectionBaseAttribute
当一个GameObject含有使用了该属性的Component的时候,在SceneView中选择该GameObject,Hierarchy上面会自动选中该GameObject的Parent
SerializeField
可以强制该变量进行序列化
SharedBetweenAnimatorsAttribute
用于StateMachineBehaviour上,不同的Animator将共享这一个StateMachineBehaviour的实例,可以减少内存占用
[SharedBetweenAnimators]
public class AttackBehaviour : StateMachineBehaviour
{
  public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
  {
  Debug.Log("OnStateEnter");
  }
}
SpaceAttribute
在Inspector上增加一些空位
TextAreaAttribute
把string在Inspector上的编辑区变成一个TextArea
TooltipAttribute
当鼠标指针移动到Inspector上时候显示
UnityAPICompatibilityVersionAttribute
用来声明API的版本兼容性 

Sharezer , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明UnityEngine Attributes
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址