unity3dMonoBehaviour章节中文翻译_第1页
unity3dMonoBehaviour章节中文翻译_第2页
unity3dMonoBehaviour章节中文翻译_第3页
unity3dMonoBehaviour章节中文翻译_第4页
unity3dMonoBehaviour章节中文翻译_第5页
已阅读5页,还剩49页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、MonoBehaviourInherits from Behaviour继承自BehaviourMonoBehaviour 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脚本自动继承 MonoBehavio

2、ur.使用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(),

3、 Awake(), Update(), FixedUpdate(), 和 OnGUI()函数 时显示,没有这些函数时则隐藏.(另注:译者在PC上Windows平台测试结果与此注释所描述情况不符)See Also: The chapter on scripting in the manual.VariablesuseGUILayoutDisabling this lets you skip the GUI layout phase.禁用此项,将会跳过GUILayout部署Functions 函数InvokeInvokes the method methodName in time seconds

4、.根据时间调用指定方法名的方法InvokeRepeatingInvokes the method methodName in time seconds.根据时间调用指定方法名的方法CancelInvokeCancels all Invoke calls on this MonoBehaviour.取消这个MonoBehaviour上的所有调用.IsInvokingIs any invoke on methodName pending?某指定函数是否在等候调用StartCoroutineStarts a coroutine.开始协同程序.StopCoroutineStops all corout

5、ines named methodName running on this behaviour.停止这个动作中名为methodName的所有协同程序.StopAllCoroutinesStops all coroutines running on this behaviour.停止所有动作的协同程序.Overridable Functions可重载的函数UpdateUpdate is called every frame, if the MonoBehaviour is enabled.当MonoBehaviour启用时,其Update在每一帧被调用LateUpdateLateUpdate i

6、s called every frame, if the Behaviour is enabled.当MonoBehaviour启用时,其LateUpdate在每一帧被调用FixedUpdateThis function is called every fixed framerate frame, if the MonoBehaviour is enabled.当MonoBehaviour启用时,其FixedUpdate在每一帧被调用AwakeAwake is called when the script instance is being loaded.当一个脚本实例被载入时Awake被调用

7、.StartStart is called just before any of the Update methods is called the first time.Start在Update调用前被调用.ResetReset to default values.重置,恢复到默认值.OnMouseEnterOnMouseEnter is called when the mouse entered the GUIElement or Collider.当鼠标进入到 GUIElement(GUI组件)或Collider(碰撞体)中时调用OnMouseEnter.OnMouseOverOnMous

8、eOver is called every frame while the mouse is over theGUIElement or Collider.OnMouseOver .当鼠标悬浮在GUIElement(GUI组件域Collider(碰撞体)上时调用OnMouseExitOnMouseExit is called when the mouse is not any longer over theGUIElement or Collider.当鼠标移出GUIElement(GUI组件)或Collider(碰撞体)上时调用OnMouseExitOnMouseDownOnMouseDow

9、n is called when the user has pressed the mouse button while over theGUIElement orCollh当用户在GUIElement(GUI组件域Collider(碰撞体)上点击鼠标时调用 OnMouseDownOnMouseUpOnMouseUp is called when the user has released the mouse button.用户释放鼠标键的时候调用这个OnMouseDragOnMouseDrag is called when the user has clicked on a GUIEleme

10、nt or Collider and is still holding down thmouse.当用户鼠标拖拽GUIElement(GUI组件域Collider(碰撞体)时调用OnMouseDragOnTriggerEnterOnTriggerEnter is called when the Collider other enters the trigger.当Collider(碰撞体)进入trigger(触发器)时调用OnTriggerEnter.OnTriggerExitOnTriggerExit is called when the Collider other has stopped

11、 touching the trigger.当Collider(碰撞体)移出trigger(触发器)时调用OnTriggerExit.OnTriggerStayOnTriggerStay is called once per frame for every Collider other that is touching the trigger.当Collider(碰撞体)触发trigger(触发器)时在每一帧调用OnTriggerStay.OnCollisionEnterOnCollisionEnter is called when this collider/rigidbody has be

12、gun touching another rigidbody/collider.当此 collider/rigidbody 触发另一个 rigidbody/collider 时,OnCollisionEnter 将被调用.OnCollisionExitOnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.OnCollisionStayOnControllerColliderHitOnJointBreakOnParticleCollisionOn

13、BecameVisibleOnBecameInvisibleOnLevelWasLoadedOnEnableOnDisableOnPreCull当此 collider/rigidbody 停止触发另一个 rigidbody/collider 时,OnCollisionExit 将被调用.OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.当此 collider/rigidbody 触发另一个 rigidbody/collider 时,O

14、nCollisionStay 将会在每一帧被调用OnControllerColliderHit is called when the controller hits a collider while performing a Move.当 controller 碰撞到 collider 时 OnControllerHit 被调用.Called when a joint attached to the same game object broke.当附在同一对象上的关节被断开时调用OnParticleCollision is called when a particle hits a colli

15、der.当粒子碰到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

16、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.当对象变为不可用或非激活状态时此函数被调用OnPreCull is called before a camera culls the scene.在相机剪裁场景之前被调用OnPreRenderOnPreRende

17、r is called before a camera starts rendering the scene.在相机渲染场景之前被调用.OnPostRenderOnPostRender is called after a camera finished rendering the scene.在相机完成场景渲染之后被调用.OnRenderObjectOnRenderObject is called after camera has rendered the scene.在相机场景渲染完成后被调用OnWillRenderObjectOnWillRenderObject is called onc

18、e for each camera if the object is visible.如果对象可见每个相机都会调用它.OnGUIOnGUI is called for rendering and handling GUI events.渲染和处理GUI事件时调用.OnRenderImageOnRenderImage is called after all rendering is complete to render image当完成所有渲染后被调用,用来渲染图片后期效果OnDrawGizmosSelectedImplement this OnDrawGizmosSelected if you

19、 want to draw gizmos only if the object is selected.如果你想在物体被选中时绘制gizmos,去实现这个函数OnDrawGizmosImplement this OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn.如果你想绘制可被点选的gizmos,去实现这个.OnApplicationPauseSent to all game objects when the player pauses.当玩家暂停时发送到所有的游戏物体OnApplic

20、ationFocusSent to all game objects when the player gets or looses focus.当玩家获取或失去焦点时发送给所有游戏物体OnApplicationQuitSent to all game objects before the application is quit.在应用退出之前发送给所有的游戏物体OnPlayerConnectedCalled on the server whenever a new player has successfully connected.当一个新玩家成功连接时在服务器上被调用OnServerInit

21、ializedCalled on the server whenever a Network.InitializeServer was invoked and has completed.当Network.InitializeServer被调用并完成时,在服务器上调用这个函数OnConnectedToServerCalled on the client when you have successfully connected to a server当你成功连接到服务器时,在客户端被调用.OnPlayerDisconnectedCalled on the server whenever a pl

22、ayer disconnected from the server.当一个玩家从服务器上断开时在服务器端调用OnDisconnectedFromServerCalled on the client when the connection was lost or you disconnected from the server.当失去连接或从服务器端断开时在客户端调用OnFailedToConnectCalled on the client when a connection attempt fails for some reason.当一个连接因为某些原因失败时在客户端调用OnFailedTo

23、ConnectToMasterServerCalled on clients or servers when there is a problem connecting to the MasterServer.当连接主服务器出现问题时在客户端或服务器端调用OnMasterServerEventCalled on clients or servers when reporting events from the MasterServer.当报告事件来自主服务器时在客户端或服务器端调用OnNetworkInstantiateCalled on objects which have been net

24、work instantiated with Network.InstantiateOnSerializeNetworkView当一个物体使用Network.Instantiate进行网络初始化时调用.Used to customize synchronization of variables in a script watched by a network view.在一个网络视图脚本中,用于自定义变量同步Class Functions 类函数printLogs message to the Unity Console. This function is identical toDebug.

25、Log .记录消息到Unity控制台.这个函数和Debug.Log作用相同.Inherited members被继承的成员Inherited Variables 被继承的变量enabledEnabled Behaviours are Updated, disabled Behaviours are not.启用时Behaviours会执行更新,反之不更新.transformThe Transform attached to this GameObject (null if there is none attached).附加在本游戏对象上的Transform(没有则为null).rigidbo

26、dyThe Rigidbody attached to this GameObject (null if there is none attached).附加在本游戏对象上的Rigidbody (没有则为null).cameraThe Camera attached to this GameObject (null if there is none attached).附加在本游戏对象上的Camera (没有则为null).lightThe Light attached to this GameObject (null if there is none attached).附加在本游戏对象上的

27、Light (没有则为null).animationThe Animation attached to this GameObject (null if there is none attached).附加在本游戏对象上的animation (没有则为null).constantForceThe ConstantForce attached to this GameObject (null if there is none attached).附加在本游戏对象上的ConstantForce(没有则为null).rendererThe Renderer attached to this Game

28、Object (null if there is none attached).附加在本游戏对象上的Renderer (没有则为null).audioThe AudioSource attached to this GameObject (null if there is none attached).附加在本游戏对象上的AudioSource (没有则为null).guiTextThe GUIText attached to this GameObject (null if there is none attached).附加在本游戏对象上的GUIText (没有则为null).networ

29、kViewThe NetworkView attached to this GameObject (Read Only). (null if there is none attached)附加在本游戏对象上的NetworkView (只读)(没有则为null).guiTextureThe GUITexture attached to this GameObject (Read Only). (null if there is none attached)附加在本游戏对象上的GUITexture (只读)(没有则为null).colliderThe Collider attached to th

30、is GameObject (null if there is none attached).附加在本游戏对象上的Collider (没有则为null).hingeJointThe HingeJoint attached to this GameObject (null if there is none attached).附加在本游戏对象上的HingeJoint (没有则为null).particleEmitterThe ParticleEmitter attached to this GameObject (null if there is none attached).附加在本游戏对象上

31、的ParticleEmitter(没有则为null).gameObjectThe game object this component is attached to. A component is always attached to a game object.该组件附加的游戏对象.组件总是附加在一个游戏对象上.tagThe tag of this game object.该游戏对象的标签.nameThe name of the object.该游戏对象的名字.hideFlagsShould the object be hidden, saved with the scene or modi

32、fiable by the user?设置是否隐藏,保存在场景中或被用户修改.Inherited Functions 被继承的函数GetComponentReturns the component of Type type if the game object has one attached, null if it doesn't.返回游戏对象上某类型的组件.没有则返回null.GetComponentInChildrenReturns the component of Type type in the GameObject or any of its children using

33、depth first search.返回游戏对象或其子物体上某类型的组件.没有则返回null.搜素时深度优先.GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children.返回游戏对象或其子物体上所有某类型的组件GetComponentsReturns all components of Type type in the GameObject .返回游戏对象上某类型的所有组件.CompareTagIs this game object tagged tag

34、?核对游戏对象的标签SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this game object and on every ancestor of theBehaviour在该游戏对象的所有MonoBehaviour上及其父物体上调用名为methodName的方法,SendMessageCalls the method named methodName on every MonoBehaviour in this game object.在该游戏对象的所有 MonoBehaviour

35、上调用名为 methodName的方法,BroadcastMessageCalls the method named methodName on every MonoBehaviour in this game object or any of its children.在该游戏对象的所有MonoBehaviour上及其子物体上调用名为 methodName的方法,GetInstancelDReturns the instance id of the object.返回该物体的实例ID.Inherited Class Functions被继承的类函数operator boolDoes the

36、object exist?判断物体是否存在.InstantiateClones the object original and returns the clone.复制一个物体并返回该备份.DestroyRemoves a gameobject, component or asset.移除一个物体,组件或资源.DestroyImmediateDestroys the object obj immediately. It is strongly recommended to use Destroy instead.立刻销毁一个物体.建议用Destroy代替之.FindObjectsOfTypeR

37、eturns a list of all active loaded objects of Type type.返回找到的所有指定类型的对象.FindObjectOfTypeReturns the first active loaded object of Type type.返回找到的指定类型的第一个对象operator =Compares if two objects refer to the same比较两个物体是否相同.operator !=Compares if two objects refer to a different object比较两个物体是否不同.DontDestroy

38、OnLoadMakes the object target not be destroyed automatically when loading a new scene.确保目标对象在加载新场景时不被自动销毁MonoBehaviour .useGUILayoutDescriptionDisabling this lets you skip the GUI layout phase.禁用此项,将会跳过GUILayout部署阶段It can only be used if you do not use GUI.Window and GUILayout inside of this OnGUI c

39、all.它只用于在假如你不用GUI.Window和GUILayout的时候.MonoBehaviour .Invokefunction Invoke (methodName : string, time : float) : voidDescriptionInvokes the method methodName in time seconds.根据时间调用指定方法名的方法.JavaScript/ Launches a projectile in 2 seconds/ 2秒后发射炮弹var projectile : Rigidbody ;Invoke("LaunchProjectil

40、e", 2);function LaunchProjectile () var instance : Rigidbody = Instantiate(projectile);instance.velocity =Random.insideUnitSphere* 5;MonoBehaviour.InvokeRepeatingfunction InvokeRepeating (methodName :string , time : float, repeatRate : float) : voidDescriptionInvokes the method methodName in ti

41、me seconds.根据时间调用指定方法名的方法After the first invocation repeats calling that function every repeatRate seconds.从第一次调用开始,每隔repeatRate时间调用一次.JavaScript/ Starting in 2 seconds./ a projectile will be launched every 0.3 seconds/ 2秒后开始/每0.3秒发射一颗炮弹var projectile : Rigidbody ;InvokeRepeating("LaunchProject

42、ile", 2, 0.3);function LaunchProjectile () var instance : Rigidbody = Instantiate(projectile);instance.velocity =Random.insideUnitSphere* 5;)MonoBehaviour.Cancellnvokefunction Cancellnvoke () : voidDescriptionCancels all Invoke calls on this MonoBehaviour.取消这个MonoBehaviour上的所有调用.JavaScript/ Sta

43、rting in 2 seconds./ a projectile will be launched every 0.3 seconds/ 2秒后开始/每0.3秒发射一颗炮弹var projectile : Rigidbody ;InvokeRepeating("LaunchProjectile", 2, 0.3);/ Cancels the repeating invoke call,/ when the user pressed the ctrl button/当用户按下ctrl键取消repeating调用function Update() if ( Input.Get

44、Button ("Firel") CancelInvoke();)function LaunchProjectile () instance = Instantiate(projectile);instance.velocity = Random.insideUnitSphere * 5;)function CancelInvoke (methodName : string ) : voidDescriptionCancels all Invoke calls with name methodName on this behaviour.取消所有名为methodName的调

45、用.JavaScript/ Starting in 2 seconds./ a projectile will be launched every 0.3 seconds/ 2秒后开始/每0.3秒发射一颗炮弹var projectile : Rigidbody ;InvokeRepeating("LaunchProjectile", 2, 0.3);/ Cancels the repeating invoke call,/ when the user pressed the ctrl button/当用户按下ctrl键取消repeating调用function Update

46、() if ( Input.GetButton ("Fire1")CancelInvoke("LaunchProjectile");)function LaunchProjectile () instance = Instantiate(projectile);instance.velocity =Random.insideUnitSphere* 5;)MonoBehaviour.IsInvokingDescriptionIs any invoke on methodName pending?某指定函数是否在等候调用.JavaScript/ Instan

47、tiates a project after 2 seconds whenSpace key was pressed/ and it will only call the function after the function has ended its execution/按下空格键2秒后实例化一个炮弹,在该函数执行完毕之前仅调用此函数var projectile : Rigidbody ;function Update() if( Input.GetKeyDown ( KeyCode.Space ) && !IsInvoking("LaunchProjectile

48、")Invoke(''LaunchProjectile'', 2); )function LaunchProjectile () (var instance : Rigidbody = Instantiate(projectile);instance.velocity = Random.insideUnitSphere * 5; ) function IsInvoking () : boolDescriptionIs any invoke pending on this MonoBehaviour?此MonoBehaviour上是否有调用在等候.Mon

49、oBehaviour .StartCoroutinefunction StartCoroutine (routine : IEnumerator) :CoroutineDescriptionStarts a coroutine.开始协同程序.The execution of a coroutine can be paused at any point using the yield statement. The yield return value specifies when the coroutine is resumed. Coroutines are excellent when mo

50、delling behaviour over several frames. Coroutines have virtually no performance overhead. StartCoroutine function always returns immediately, however you can yield the result. This will wait until the coroutine has finished execution.一个协同程序在执行过程中,可以在任意位置使用yield语句.yield的返回值控制何时恢复协同程序向下执行.协同程序在 对象自有帧执

51、行过程中堪称优秀.协同程序在性能上没有更多的开销.StartCoroutine函数是立刻返回的,但是yield可以延 迟结果.直到协同程序执行完毕.When using JavaScript it is not necessary to use StartCoroutine, the compiler will do this for you. When writing C# code you must call StartCoroutine.用javascript不需要添加StartCoroutine,编译器将会替你完成.但是在C#下,你必须调用StartCoroutine.JavaScri

52、pt/ In this example we show how to invoke a coroutine and continue executing/ the function in parallel./此例演示如何调用协同程序和它的执行function Start() (/ - After 0 seconds, prints "Starting 0.0"/ - After 0 seconds, prints "Before WaitAndPrint Finishes 0.0"/ - After 2 seconds, prints "Wai

53、tAndPrint 2.0"/ 先打印"Starting 0.0" 和"Before WaitAndPrint Finishes 0.0" 两句,2 秒后打印"WaitAndPrint 2.0" print ("Starting " + Time.time );/ Start function WaitAndPrint as a coroutine. And continue execution while it is running/ this is the same as WaintAndPrint(

54、2.0) as the compiler does it for you automatically/协同程序WaitAndPrint 在Start函数内执行,可以视同于它与Start函数同步执行.StartCoroutine(WaitAndPrint(2.0);print ("Before WaitAndPrint Finishes " +Time.time );function WaitAndPrint (waitTime : float) / suspend execution for waitTime seconds/暂停执行waitTime 秒yield Wait

55、ForSeconds (waitTime);print ("WaitAndPrint "+ Time.time );Another Example:JavaScript/ In this example we show how to invoke a coroutine and wait until it/ is completed/在这个例子中我们演示如何调用协同程序并直到它执行完成.function Start() / - After 0 seconds, prints "Starting 0.0"/ - After 2 seconds, prints "WaitAndPrint 2.0"/ - After 2 seconds, prints "Done 2.0"/ 0 秒时打印“Starting 0.0",2秒后打印"WaitAndPrint 2.

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论