[ExecuteInEditMode]
// Make code live-update even when not in play mode
[ContextMenu("Execute")]
[RequireComponent (typeof (Rigidbody))]
如果没有Rigidbody组件就自动添加
[AddComponentMenu("MyPhysic/PhysicType")]
public class PhysicType: MonoBehaviour{
}
原本的脚本(组建)都会在“Component/Script”菜单下,在类之前声明一下这个,它便可以出现在"Componet"菜单下的任何位置
ExecuteInEditMode
当我们为MonoBehavior定义了[ExecuteInEditMode]后,我们需要关心Awake和Start在编辑器中的执行状况。
1、当该MonoBehavior在编辑器中被赋于给GameObject的时候,Awake, Start 将被执行。
2、当Play按钮被按下游戏开始以后,Awake, Start 将被执行。
3、当Play按钮停止后,Awake, Start将再次被执行。
4、当在编辑器中打开包含有该MonoBehavior的场景的时候,Awake, Start将被执行。