unity api中文手册_Unity手册—Attribute汇总说明

内容取自官方API文档特性说明部分,用于开发参考,辅助开发提升开发效率;特性(Attribute)作用于脚本中的类、变量或方法的上,用[ ]包裹,用于表明其特殊行为,如 [HideInInspector],使变量在 Inspector 面板隐藏; 部分特性还未使用过,且网上资料很少,所以欠缺解释,后期补足本文原地址:Unity手册—Attribute汇总说明引用版本:Unity 官方手册 ver...
摘要由CSDN通过智能技术生成

内容取自官方API文档特性说明部分,用于开发参考,辅助开发提升开发效率;特性(Attribute)作用于脚本中的类、变量或方法的上,用[ ]包裹,用于表明其特殊行为,如 [HideInInspector],使变量在 Inspector 面板隐藏;

部分特性还未使用过,且网上资料很少,所以欠缺解释,后期补足

本文原地址:Unity手册—Attribute汇总说明

引用版本:Unity 官方手册 ver. 2020.1 UnityEngine API文档 UnityEditor API文档 .NET特性文档

常用特性

此处列出常用特性,功能说明在下方汇总

菜单 Menu

  • AddComponentMenu
  • MenuItem
  • CreateAssetMenuAttribute

监视器 Inspector

  • HeaderAttribute
  • HideInInspector
  • InspectorNameAttribute
  • SpaceAttribute
  • TextAreaAttribute
  • TooltipAttribute
  • ContextMenu
  • ContextMenuItemAttribute

对象/变量 Class/Property

  • ColorUsageAttribute
  • DisallowMultipleComponent
  • MinAttribute
  • RangeAttribute
  • RequireComponent
  • SerializeField
  • Serializable
  • NonSerialized

其他

  • PostProcessBuildAttribute
  • PostProcessSceneAttribute
  • InitializeOnLoadAttribute
  • InitializeOnLoadMethodAttribute
  • UnityAPICompatibilityVersionAttribute

官方文档特性汇总

UnityEngine Attributes

  • AddComponentMenu

参数:menuName 菜单名称

作用于类上,将脚本置于 UnityEditor 顶部菜单栏 Component 菜单中的任意选项,而不局限于 Component->Scripts 选项下

将脚本置于 UnityEditor 顶部菜单栏 Component 菜单中的任意选项,而不局限于 Component->Scripts 选项下

[AddComponentMenu("WarlGComponent/WarlGAttribute")]   
public class WarlGAttributeSample : MonoBehaviour   {
       }

06b68143aa742ae4f4fc5107f2d648f2.png

9e038d95739395d12429d3f0e35f8961.png
  • AssemblyIsEditorAssembly

作用于程序集,具有此属性的程序集中的任何类将被视为编辑器类

  • BeforeRenderOrderAttribute

参数: order 调用顺序

作用于方法上,被作用的方法会被注册为 Application.onBeforeRender 的事件回调,以给定顺序从低到高顺序调用

  • ColorUsageAttribute

参数:showAlpha 是否显示 Alpha 配置项、HDR 是否高动态范围

作用于 Color 类型变量上,使其可在取色面板配置显示 Alpha 和采用 HDR 标准

[ColorUsage(true,true)]    
public Color colorpicker;

804991fade71aa604a4d1887664aff3a.png
  • ContextMenu

参数:itemName 菜单项名称

作用于非静态方法上,在脚本 Inspector 的 context menu 上添加额外操作(Inspector 上脚本右击菜单)

[ContextMenu("WarlG Context Menu")]   
void CustomContext()   
{
         
    Debug.Log("WarlGContext");   
} 

0f90e1501cb445d808c2894b6a3dc920.png
  • ContextMenuItemAttribute

参数:name 菜单名、function 方法名

作用于变量上,给作用的变量在Inspector上添加右键菜单方法

[ContextMenuItem("ResetString", "ResetSampleString")]   
public st
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值