Unity3D Script脚本编辑器属性

本文介绍了Unity3D Script脚本编辑器的9种关键属性,包括AddComponentMenu用于定制组件菜单,ContextMenu用于创建上下文菜单,ExecuteInEditMode使脚本在编辑模式下运行,HideInInspector隐藏检视面板中的变量,NonSerialized阻止变量序列化,RPC实现远程过程调用,SerializeField强制序列化私有字段,RequireComponent自动添加依赖组件,Serializable允许在检视面板中嵌套显示类属性。
摘要由CSDN通过智能技术生成

Script Attributes:基于IDE的一系列编译器属性

JS	@Script 属性方法()
C#	[属性方法()]

Unity3D Script脚本编辑器属性一共有9种

(1)AddComponentMenu 添加组件菜单

The AddComponentMenu attribute allows you to place a script anywhere in the "Component" menu, instead of just the "Component->Scripts" menu.

You use this to organize the Component menu better, this way improving workflow when adding scripts. Important notice: You need to restart.

[AddComponentMenu("Transform/Follow Transform")]
public class FollowTransform : MonoBehaviour
{
}

(2)ContextMenu 上下文菜单

The ContextMenu attribute allows you to add commands to the context menu.

In the inspector of the attached script. When the user selects the context menu, the function will be executed.

This is most useful for automatically setting up scene data from the script. The function has to be non-static.

public class ContextTesting : MonoBehaviour {
	/// Add a context menu named "Do Something" in the inspector
	/// of the attached script.
	[ContextMenu ("Do Something")]
	void DoSomething () {
		Debug.Log ("Perform operation");
	}
}


(3)ExecuteInEditMode 在编辑模式下运行

Makes a script execute in edit mode.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值