Unity脚本类为什么要尽量避免继承monobehaviour 事件类

MonoBehaviour Mono行为
Inherits from
MonoBehaviour is the base class every script
derives from.
MonoBehaviour是每个脚本的基类.
Using Javascript every script automatically
derives from MonoBehaviour. When using C# or Boo you have to explicitly derive
from MonoBehaviour.
每个Javascript脚本自动继承MonoBehaviour,使用C#或Boo时,需要显式继承MonoBehaviour.
Note: The checkbox for
disabling a MonoBehavior (on the editor) will only prevent Start(), Awake(),
Update(), FixedUpdate(), and OnGUI() from executing. If none of these functions
are present, the checkbox is not displayed.
注意:MonoBehavior对象(编辑器中)的复选框,只有在其有Start(),Awake(),Update(),
FixedUpdate()和 OnGUI()函数时显示,没有这些函数时则隐藏。(另注:译者在PC上Windows平台测试结果与此注释所描述情况不符)
Variables变量
Disabling this lets you skip the GUI layout phase.
禁用此项,将会跳过GUILayout布局阶段。
Functions函数
Invokes the method methodName in time seconds.
在time秒调用methodName方法;简单说,根据时间调用指定方法名的方法
Invokes the method methodName in time seconds.
在time秒调用methodName方法;简单说,每隔指定时间调用指定方法名的方法
Cancels all Invoke calls on this MonoBehaviour.
取消这个MonoBehaviour上的所有调用。
Is any invoke on methodName pending?
某指定函数是否在等候调用。
Starts a coroutine.
开始协同程序。
Stops all coroutines named methodName running on this behaviour.
停止这个动作中名为methodName的所有协同程序
Stops all coroutines running on this behaviour.
停止所有动作的协同程序
Overridable Functions可重写函数
Update is called every frame, if the MonoBehaviour is enabled.
当MonoBehaviour启用时,其Update在每一帧被调用。
LateUpdate is called every frame, if the Behaviour is enabled.
当Behaviour启用时,其LateUpdate在每一帧被调用。
This function is called every fixed framerate frame, if the MonoBehaviour is enabled.
当MonoBehaviour启用时,其 在每一帧被调用。
Awake is called when the script instance is being loaded.
当一个脚本实例被载入时Awake被调用。
Start is called just before any of the Update methods is called the first time.
Start仅在Update函数第一次被调用前调用。
Reset to default values.
重置为默认值。
OnMouseEnter is called when the mouse entered the GUIElement or Collider.
当鼠标进入到GUIElement(GUI元素)或Collider(碰撞体)中时调用OnMouseEnter。
OnMouseOver is called every frame while the mouse is over the GUIElement or Collider.
当鼠标悬浮在GUIElement(GUI元素)或Collider(碰撞体)上时调用 .
OnMouseExit is called when the mouse is not any longer over the GUIElement or Collider.
当鼠标移出GUIElement(GUI元素)或Collider(碰撞体)上时调用OnMouseExit。
OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.
当鼠标在GUIElement(GUI元素)或Collider(碰撞体)上点击时调用OnMouseDown。
OnMouseUp is called when the user has released the mouse button.
当用户释放鼠标按钮时调用OnMouseUp。
OnMouseUpAsButton is only called when the mouse is released over the same
as it was pressed.
OnMouseUpAsButton只有当鼠标在同一个或按下,在释放时调用。
OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
当用户鼠标拖拽GUIElement(GUI元素)或Collider(碰撞体)时调用 。
OnTriggerEnter is called when the Collider other enters the trigger.
当Collider(碰撞体)进入trigger(触发器)时调用OnTriggerEnter。
OnTriggerExit is called when the Collider other has stopped touching the trigger.
当Collider(碰撞体)停止触发trigger(触发器)时调用OnTriggerExit。
OnTriggerStay is called once per frame for every Collider other that is touching the trigger.
当碰撞体接触触发器时,OnTriggerStay将在每一帧被调用。
OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
当此collider/rigidbody触发另一个rigidbody/collider时,OnCollisionEnter将被调用。
OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
当此collider/rigidbody停止触发另一个rigidbody/collider时,OnCollisionExit将被调用。
OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.
当此collider/rigidbody触发另一个rigidbody/collider时,OnCollisionStay将会在每一帧被调用。
OnControllerColliderHit is called when the controller hits a collider while performing a Move.
在移动的时,当controller碰撞到collider时OnControllerColliderHit被调用。
Called when a joint attached to the same game object broke.
当附在同一对象上的关节被断开时调用。
OnParticleCollision is called when a particle hits a collider.
当粒子碰到collider时被调用。
OnBecameVisible is called when the renderer became visible by any camera.
当renderer(渲染器)在任何相机上可见时调用OnBecameVisible。
OnBecameInvisible is called when the renderer is no longer visible by any camera.
当renderer(渲染器)在任何相机上都不可见时调用OnBecameInvisible。
This function is called after a new level was loaded.
当一个新关卡被载入时此函数被调用。
This function is called when the object becomes enabled and active.
当对象变为可用或激活状态时此函数被调用。
This function is called when the behaviour becomes disabled () or inactive.
当对象变为不可用或非激活状态时此函数被调用。
This function is called when the MonoBehaviour will be destroyed.
当MonoBehaviour将被销毁时,这个函数被调用。
OnPreCull is called before a camera culls the scene.
在相机消隐场景之前被调用。
OnPreRender is called before a camera starts rendering the scene.
在相机渲染场景之前被调用。
OnPostRender is called after a camera finished rendering the scene.
在相机完成场景渲染之后被调用。
OnRenderObject is called after camera has rendered the scene.
在相机场景渲染完成后被调用。
OnWillRenderObject is called once for each camera if the object is visible.
如果对象可见每个相机都会调用它。
OnGUI is called for rendering and handling GUI events.
渲染和处理GUI事件时调用。
OnRenderImage is called after all rendering is complete to render image
当完成所有渲染图片后被调用,用来渲染图片后期效果。
Implement this OnDrawGizmosSelected if you want to draw gizmos only if the object is selected.
如果你想在物体被选中时绘制gizmos,执行这个函数。
Implement this OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn.
如果你想绘制可被点选的gizmos,执行这个函数。
Sent to all game objects when the player pauses.
当玩家暂停时发送到所有的游戏物体。
Sent to all game objects when the player gets or looses focus.
当玩家获得或失去焦点时发送给所有游戏物体。
Sent to all game objects before the application is quit.
在应用退出之前发送给所有的游戏物体。
Called on the server whenever a new player has successfully connected.
当一个新玩家成功连接时在服务器上被调用。
Called on the server whenever a Network.InitializeServer was invoked and has completed.
当Network.InitializeServer被调用并完成时,在服务器上调用这个函数。
Called on the client when you have successfully connected to a server
当你成功连接到服务器时,在客户端调用。
Called on the server whenever a player disconnected from the server.
当一个玩家从服务器上断开时在服务器端调用。
Called on the client when the connection was lost or you disconnected from the server.
当失去连接或从服务器端断开时在客户端调用。
Called on the client when a connection attempt fails for some reason.
当一个连接因为某些原因失败时在客户端调用。
Called on clients or servers when there is a problem connecting to the MasterServer.
当报告事件来自主服务器时在客户端或服务器端调用。
Called on clients or servers when reporting events from the MasterServer.
当报告事件来自主服务器时在客户端或服务器端调用。
Called on objects which have been network instantiated with Network.Instantiate
当一个物体使用Network.Instantiate进行网络初始化时调用。
Used to customize synchronization of variables in a script watched by a network view.
在一个网络视图脚本中,用于自定义变量同步。
Class Functions类函数
Logs message to the Unity Console. This function is identical to Debug.Log.
记录消息到Unity控制台,这个函数和Debug.Log作用相同。
Inherited members继承成员
Inherited Variables继承变量
Enabled Behaviours are Updated, disabled Behaviours are not.
启用行为被更新,禁用行为不更新。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(Read Only). (null if there is none attached)
附加到(游戏物体)(只读)(如无附加则为空)。
attached to this
(Read Only). (null if there is none attached)
附加到(游戏物体)(只读)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
attached to this
(null if there is none attached).
附加到(游戏物体)(如无附加则为空)。
The game object this component is attached to. A component is always attached to a game object.
组件附加的游戏物体。一个组件总是被附加到一个游戏物体。
The tag of this game object.
游戏物体的标签。
The name of the object. //物体的名字
Should the object be hidden, saved with the scene or modifiable by the user?
物体是否被隐藏、保存在场景中或被用户修改?
Inherited Functions继承函数
Returns the component of Type type if the game object has one attached, null if it doesn't.
如果游戏物体有一个附加,则返回Type类型的组件,如果没有则为null。
Returns the component with name type if the game object has one attached, null if it doesn't.
如果游戏物体有一个附加,则返回名字类型组件,如果没有则为null。
Returns the component of Type type in the
or any of its children using depth first search.
返回Type类型组件,在或它的任何子物体使用深度优先搜索,仅返回激活的组件。
Returns all components of Type type in the
or any of its children.
在或任何它的子物体,返回全部Type类型组件
Returns all components of Type type in the .
在游戏物体返回全部Type类型组件。
Is this game object tagged tag?
游戏物体有被标记标签么?
Calls the method named methodName on every
in this game object and on every ancestor of the behaviour
在游戏物体每一个和每一个behaviour的祖先上调用名为methodName的方法。
Calls the method named methodName on every
in this game object.
在游戏物体每一个上调用名为methodName的方法。
Calls the method named methodName on every
in this game object or any of its children.
在游戏物体每一个和它的全部子物体上调用名为methodName的方法。
Returns the instance id of the object.
返回物体的实例ID
Returns the name of the game object.返回游戏物体的名称。
Inherited Class Functions继承类函数
Removes a gameobject, component or asset.
删除一个游戏物体、组件或资源
Destroys the object obj immediately. It is strongly recommended to use Destroy instead.
立即销毁物体obj,强烈建议使用Destroy代替。
Makes the object target not be destroyed automatically when loading a new scene.
加载新场景的时候使目标物体不被自动销毁。
Returns the first active loaded object of Type type.
返回Type类型第一个激活的加载的物体。
Returns a list of all active loaded objects of Type type.
返回Type类型的所有激活的加载的物体列表
Clones the object original and returns the clone.
克隆原始物体,并返回克隆的物体
本脚本参考基于Unity 3.4.1f5英文部分版权属&公司所有,中文部分&
版权所有,未经许可,严禁转载 。unity基类和一些函数
unity3d文档里虽然说所有脚本继承MonoBehaviour类,但是你如果想自定义类,就可以不用继承MonoBehaviour,但是可以类只能调用其中的方法和属性,无法拖到场景的物体中使用。
MonoBehaviour里面的几十方法比如
Start(), Awake(), Update(), FixedUpdate(), OnGUI(),这几个方法不管你用哪一个,必须要继承MonoBehaviour
用不用MonoBehaviour关键看要实现什么功能和属性,如果你的类不需要引擎提供的初始化,各种物理,渲染,着色器的回调,最好不要继承MonoBehaviour,游戏是需要优化节约资源的,如果你本身不需要那些功能,继承后,当引擎接触事件,触发的时候,就会反射调用个各种函数,这是很需要耗费资源的,不管咋样,GameObject还是要继承MonoBehaviour的,这样才能new实例化一个对象,但是其他类不要继承就行了。
如果不继承Mono会有那些坏处呢?
1:不能使用Invoke和Coroutine了。
2:调试不方便了,不能在Inspector和Debug tab看到参数。同时如果一个类不继承Mono,那么这个类的List表也无法在Debug界面看到。
3:不是自动调用Start,Update等方法。
继承Mono会有一个BUG:
如果你继承了Mono的类,你就不需要创建它的实例了,但是你不能new创建了,虽然编译可以通过,但是执行的时候就会有个一个错误显示在edit的console窗口,这时候不管你new后面有是否为空,但是系统显示为空,这就是一个BUG了,我的类继承了你,虽然不能new出来,但是怎么会是一个错误呢。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2758次
排名:千里之外
(1)(1)(12)

我要回帖

更多关于 monobehaviour 事件 的文章

 

随机推荐