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.