zoukankan      html  css  js  c++  java
  • unity3d API汇总

      1 using UnityEngine;
      2 using System.Collections;
      3 
      4 public class AllFunction : MonoBehaviour
      5 {
      6     /*
      7         API Version: 4.3
      8      *  Count:60
      9      */
     10 
     11     // Awake is called when the script instance is being loaded (Since v1.0)
     12     //当一个脚本实例被载入时Awake被调用。一般用于初始化整个实例使用。 在生命周期中只执行一次
     13     public void Awake()
     14     {
     15 
     16     }
     17 
     18     // Update is called every frame, if the MonoBehaviour is enabled (Since v1.0)
     19     /// <summary>
     20     /// 当MonoBehaviour启用时,其Update在每一帧被调用。
     21     ///Update是实现各种游戏行为最常用的函数。
     22     ///为了获取自最后一次调用Update所用的时间,可以用Time.deltaTime。这个函数只有在Behaviour启用时被调用。实现组件功能时重载这个函数。
     23     /// </summary>
     24     public void Update()
     25     {
     26 
     27     }
     28 
     29     // Start is called just before any of the Update methods is called the first time (Since v1.0)
     30     /// <summary>
     31     /// Start仅在Update函数第一次被调用前调用。
     32     ///Start在behaviour的生命周期中只被调用一次。它和Awake的不同是Start只在脚本实例被启用时调用。
     33     ///你可以按需调整延迟初始化代码。Awake总是在Start之前执行。这允许你协调初始化顺序。
     34     ///在所有脚本实例中,Start函数总是在Awake函数之后调用。
     35     /// </summary>
     36     public void Start()
     37     {
     38 
     39     }
     40 
     41     // Reset to default values (Since v1.0)
     42     /// <summary>
     43     /// 重置为默认值。
     44     ///Reset是在用户点击检视面板的Reset按钮或者首次添加该组件时被调用。
     45     ///此函数只在编辑模式下被调用。Reset最常用于在检视面板中给定一个最常用的默认值。
     46     /// </summary>
     47     public void Reset()
     48     {
     49 
     50     }
     51 
     52     // OnWillRenderObject is called once for each camera if the object is visible (Since v2.0)
     53     /// <summary>
     54     /// 如果对象可见每个相机都会调用它。
     55     ///如果MonoBehaviour被禁用,此函数将不被调用。
     56     ///此函数在消隐过程中被调用,在渲染所有被消隐的物体之前被调用。
     57     ///你可以用它来创建具有依赖性的纹理并且只有在被渲染的物体可见时才更新这个纹理。举例来讲,它已用于水组件中。
     58     ///Camera.current将被设置为要渲染这个物体的相机。
     59     /// </summary>
     60     public void OnWillRenderObject()
     61     {
     62 
     63     }
     64 
     65     // This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only). (Since v4.2)
     66     public void OnValidate()
     67     {
     68 
     69     }
     70 
     71     // OnTriggerStay2D is called once per frame for every Collider2D other that is touching the trigger (2D physics only). (Since v4.3)
     72     public void OnTriggerStay2D(Collider2D other)
     73     {
     74 
     75     }
     76 
     77     // OnTriggerStay is called once per frame for every Collider other that is touching the trigger (Since v1.0)
     78     /// <summary>
     79     /// 当碰撞体接触触发器时,OnTriggerStay将在每一帧被调用。
     80     ///这个消息被发送到触发器和接触到这个触发器的碰撞体。注意如果碰撞体附加了一个刚体,也只发送触发器事件。
     81     ///OnTriggerStay可以被用作协同程序,在函数中调用yield语句。
     82     /// </summary>
     83     /// <param name="other"></param>
     84     public void OnTriggerStay(Collider other)
     85     {
     86 
     87     }
     88 
     89     // OnTriggerExit2D is called when the Collider2D other has stopped touching the trigger (2D physics only). (Since v4.3)
     90     public void OnTriggerExit2D(Collider2D other)
     91     {
     92 
     93     }
     94 
     95     // OnTriggerExit is called when the Collider other has stopped touching the trigger (Since v1.0)
     96     /// <summary>
     97     /// 当Collider(碰撞体)停止触发trigger(触发器)时调用OnTriggerExit。
     98     ///这个消息被发送到触发器和接触到这个触发器的碰撞体。注意如果碰撞体附加了一个刚体,也只发送触发器事件。
     99     ///OnTriggerExit可以被用作协同程序,在函数中调用yield语句。
    100     /// </summary>
    101     /// <param name="other"></param>
    102     public void OnTriggerExit(Collider other)
    103     {
    104 
    105     }
    106 
    107     // OnTriggerEnter2D is called when the Collider2D other enters the trigger (2D physics only). (Since v4.3)
    108     public void OnTriggerEnter2D(Collider2D other)
    109     {
    110 
    111     }
    112 
    113     // OnTriggerEnter is called when the Collider other enters the trigger (Since v1.0)
    114     /// <summary>
    115     /// 当Collider(碰撞体)进入trigger(触发器)时调用OnTriggerEnter。
    116     ///这个消息被发送到触发器碰撞体和刚体(或者碰撞体假设没有刚体)。注意如果碰撞体附加了一个刚体,也只发送触发器事件。
    117     ///OnTriggerEnter可以被用作协同程序,在函数中调用yield语句。
    118     /// </summary>
    119     /// <param name="other"></param>
    120     public void OnTriggerEnter(Collider other)
    121     {
    122 
    123     }
    124 
    125     // Called on the server whenever a Network.InitializeServer was invoked and has completed (Since v2.0)
    126     /// <summary>
    127     /// 当Network.InitializeServer被调用并完成时,在服务器上调用这个函数。
    128     /// </summary>
    129     public void OnServerInitialized()
    130     {
    131 
    132     }
    133 
    134     // Used to customize synchronization of variables in a script watched by a network view (Since v2.0)
    135     /// <summary>
    136     /// 在一个网络视图脚本中,用于自定义变量同步。
    137     ///它自动决定被序列化的变量是否应该发送或接收,查看下面的例子获取更好的描述。
    138     ///这个依赖于谁拥有这个物体,例如,所有者发送,其他物体接收。
    139     /// </summary>
    140     /// <param name="info"></param>
    141     /// <param name="stream"></param>
    142     public void OnSerializeNetworkView(NetworkMessageInfo info, BitStream stream)
    143     {
    144 
    145     }
    146 
    147     // OnRenderObject is called after camera has rendered the scene (Since v3.0)
    148     /// <summary>
    149     /// 在相机场景渲染完成后被调用。
    150     ///该函数可以用来渲染你自己的物体,用Graphics.DrawMesh或者其他函数。这个函数类似于OnPostRender,
    151     ///除非OnRenderObject被其他物体用脚本函数调用,否则它是否附于相机都没有关系。
    152     /// </summary>
    153     public void OnRenderObject()
    154     {
    155 
    156     }
    157 
    158     // OnRenderImage is called after all rendering is complete to render image (Since v1.0)
    159     /// <summary>
    160     /// 当完成所有渲染图片后被调用,用来渲染图片后期效果。
    161     ///后期效果处理(仅Unity Pro)。
    162     ///它允许你使用基于着色器的过滤器来处理最终的图像。进入的图片是source渲染纹理。结果是destination渲染纹理。
    163     ///当有多个图片过滤器附加在相机上时,它们序列化地处理图片,将第一个过滤器的目标作为下一个过滤器的源。
    164     ///这个消息被发送到所有附加在相机上的脚本。
    165     /// </summary>
    166     /// <param name="destination"></param>
    167     /// <param name="source"></param>
    168     public void OnRenderImage(RenderTexture destination, RenderTexture source)
    169     {
    170 
    171     }
    172 
    173     // OnPreRender is called before a camera starts rendering the scene (Since v1.0)
    174     /// <summary>
    175     /// 在相机渲染场景之前被调用。
    176     ///只有脚本被附加到相机并被启用时才会调用这个函数。
    177     ///注意:如果你改变了相机的参数(如:fieldOfView),它将只作用于下一帧.应该用OnPreCull代替.OnPreRender可以是一个协同程序,在函数中调用yield语句即可.
    178     /// </summary>
    179     public void OnPreRender()
    180     {
    181 
    182     }
    183 
    184     // OnPreCull is called before a camera culls the scene (Since v1.0)
    185     /// <summary>
    186     /// 在相机消隐场景之前被调用。
    187     ///消隐决定哪个物体对于相机来说是可见的.OnPreCull仅是在这个过程被调用。
    188     ///只有脚本被附加到相机上时才会调用这个函数。
    189     ///如果你想改变相机的参数(比如:fieldOfView或者transform),可以在这里做这些。场景物体的可见性将根据相机的参数在OnPreCull之后确定。
    190     /// </summary>
    191     public void OnPreCull()
    192     {
    193 
    194     }
    195 
    196     // OnPostRender is called after a camera finished rendering the scene (Since v1.0)
    197     /// <summary>
    198     /// 在相机完成场景渲染之后被调用。
    199     ///只有该脚本附于相机并启用时才会调用这个函数。OnPostRender可以是一个协同程序,在函数中调用yield语句即。
    200     ///OnPostRender在相机渲染完所有物体之后被调用。如果你想在相机和GUI渲染完成后做些什么,就用WaitForEndOfFrame协同程序。
    201     /// </summary>
    202     public void OnPostRender()
    203     {
    204 
    205     }
    206 
    207     // Called on the server whenever a player disconnected from the server. (Since v2.0)
    208     /// <summary>
    209     /// 当一个玩家从服务器上断开时在服务器端调用。
    210     /// </summary>
    211     /// <param name="player"></param>
    212     public void OnPlayerDisconnected(NetworkPlayer player)
    213     {
    214         Debug.Log("Clean up after player " + player);
    215         Network.RemoveRPCs(player);
    216         Network.DestroyPlayerObjects(player);
    217     }
    218 
    219     // Called on the server whenever a new player has successfully connected (Since v2.0)
    220     /// <summary>
    221     /// 当一个新玩家成功连接时在服务器上被调用。
    222     /// </summary>
    223     /// <param name="player"></param>
    224     public void OnPlayerConnected(NetworkPlayer player)
    225     {
    226         int playerCount = 0;
    227         // 用玩家的信息构建一个数据结构
    228         Debug.Log("Player " + playerCount + " connected from " + player.ipAddress + ":" + player.port);
    229     }
    230 
    231     // OnParticleCollision is called when a particle hits a collider (Since v1.0)
    232     /// <summary>
    233     /// 当粒子碰到collider时被调用。
    234     ///这个可以用于游戏对象被粒子击中时应用伤害到它上面。
    235     ///这个消息被发送到所有附加到theWorldParticleCollider 的脚本上和被击中的碰撞体上。这个消息只有当你在theWorldParticleCollider 
    236     ///检视面板中启用了sendCollisionMessage 才会被发送。
    237     ///OnParticleCollision 可以被用作协同程序,在函数中调用yield语句。
    238     /// </summary>
    239     /// <param name="other"></param>
    240     public void OnParticleCollision(GameObject other)
    241     {
    242 
    243     }
    244 
    245     // Called on objects which have been network instantiated with Network.Instantiate (Since v2.0)
    246     /// <summary>
    247     /// 当一个物体使用Network.Instantiate进行网络初始化时调用。
    248     ///这对于禁用或启用一个已经初始化的物体组件来说是非常有用的,它们的行为取决于它们是在本地还是在远端。
    249     ///注意: 在NetworkMessageInfo里的networkView属性不能在OnNetworkInstantiate里使用。
    250     /// </summary>
    251     /// <param name="info"></param>
    252     public void OnNetworkInstantiate(NetworkMessageInfo info)
    253     {
    254 
    255     }
    256 
    257     // OnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed (Since v3.4)
    258     public void OnMouseUpAsButton()
    259     {
    260 
    261     }
    262 
    263     // OnMouseUp is called when the user has released the mouse button (Since v1.0)
    264     /// <summary>
    265     /// 用户释放鼠标按钮时调用OnMouseUp。
    266     ///OnMouseUp只调用在按下的同一物体上。
    267     /// </summary>
    268     public void OnMouseUp()
    269     {
    270 
    271     }
    272 
    273     // OnMouseOver is called every frame while the mouse is over the GUIElement or Collider (Since v1.0)
    274     /// <summary>
    275     /// 当鼠标悬浮在GUIElement(GUI元素)或Collider(碰撞体)上时调用 OnMouseOver 。
    276     /// </summary>
    277     public void OnMouseOver()
    278     {
    279 
    280     }
    281 
    282     // OnMouseExit is called when the mouse is not any longer over the GUIElement or Collider (Since v1.0)
    283     /// <summary>
    284     /// 当鼠标移出GUIElement(GUI元素)或Collider(碰撞体)上时调用OnMouseExit。
    285     ///OnMouseExit与OnMouseEnter相反。
    286     /// </summary>
    287     public void OnMouseExit()
    288     {
    289 
    290     }
    291 
    292     // OnMouseEnter is called when the mouse entered the GUIElement or Collider (Since v1.0)
    293     /// <summary>
    294     /// 当鼠标进入到GUIElement(GUI元素)或Collider(碰撞体)中时调用OnMouseEnter。
    295     /// 这个函数不会在属于Ignore Raycast的层上调用.
    296     ///它可以被作为协同程序,在函数体内使用yield语句.这个事件将发送到所有附在Collider或GUIElement的脚本上.
    297     ///注意:这个函数在iPhone上无效.
    298     /// </summary>
    299     public void OnMouseEnter()
    300     {
    301         // 附加这个脚本到网格
    302         // 当鼠标经过网格时网格变红色
    303         renderer.material.color = Color.red;
    304     }
    305 
    306     // OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse (Since v1.0)
    307     /// <summary>
    308     /// 当用户鼠标拖拽GUIElement(GUI元素)或Collider(碰撞体)时调用 OnMouseDrag 。
    309     ///OnMouseDrag在鼠标按下的每一帧被调用。
    310     ///这个函数不会在属于Ignore Raycast的层上调用。
    311     ///它可以被作为协同程序,在函数体内使用yield语句,这个事件将发送到所有附在Collider或GUIElement的脚本上。
    312     ///注意:此函数在iPhone上无效。
    313     /// </summary>
    314     public void OnMouseDrag()
    315     {
    316 
    317     }
    318 
    319     // OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider (Since v1.0)
    320     /// <summary>
    321     /// 当鼠标在GUIElement(GUI元素)或Collider(碰撞体)上点击时调用OnMouseDown。
    322     /// 这个事件将发送给 Collider 或 GUIElement 上的所有脚本。
    323     /// 这个函数不会在属于Ignore Raycast的层上调用.
    324     ///它可以被作为协同程序,在函数体内使用yield语句,这个事件将发送到所有附在Collider或GUIElement的脚本上。
    325     ///注意:此函数在iPhone上无效。
    326     /// </summary>
    327     public void OnMouseDown()
    328     {
    329         // 点击物体后载入"SomeLevel"关卡.
    330         Application.LoadLevel("SomeLevel");
    331     }
    332 
    333     // Called on clients or servers when reporting events from the MasterServer (Since v2.0)
    334     /// <summary>
    335     /// 当报告事件来自主服务器时在客户端或服务器端调用。
    336     /// 例如:当一个客户列表接收完成或客户注册成功后被调用。
    337     /// </summary>
    338     /// <param name="msEvent"></param>
    339     public void OnMasterServerEvent(MasterServerEvent msEvent)
    340     {
    341         if (msEvent == MasterServerEvent.RegistrationSucceeded)
    342             Debug.Log("Server registered");
    343 
    344         /*
    345             void Start() {
    346                 Network.InitializeServer(32, 25000);
    347             }
    348             void OnServerInitialized() {
    349                 MasterServer.RegisterHost("MyGameVer1.0.0_42", "My Game Instance", "This is a comment and place to store data");
    350             }
    351             void OnMasterServerEvent(MasterServerEvent msEvent) {
    352                 if (msEvent == MasterServerEvent.RegistrationSucceeded)
    353                     Debug.Log("Server registered");
    354 
    355             }
    356 
    357          */
    358     }
    359 
    360     // This function is called after a new level was loaded (Since v1.0)
    361     /// <summary>
    362     /// 当一个新关卡被载入时此函数被调用。
    363     /// "level" 是被加载的关卡的索引。使用菜单项File->Build Settings... 来查看索引引用的是哪个场景。
    364     /// OnLevelWasLoaded可以被用作协同程序,在函数中调用yield语句.
    365     /// </summary>
    366     /// <param name="level">关卡的索引</param>
    367     public void OnLevelWasLoaded(int level)
    368     {
    369         // 当关卡13被加载时打印"Woohoo"
    370         if (level == 13)
    371             print("Woohoo");
    372     }
    373 
    374     // Called when a joint attached to the same game object broke (Since v2.0)
    375     /// <summary>
    376     /// 当附在同一对象上的关节被断开时调用。
    377     ///当一个力大于这个关节的承受力时,关节将被断开。此时OnJointBreak将被调用,应用到关节的力将被传入。之后这个关节将自动从游戏对象中移除并删除。
    378     /// </summary>
    379     /// <param name="breakForce"></param>
    380     public void OnJointBreak(float breakForce)
    381     {
    382         Debug.Log("Joint Broke!, force: " + breakForce);
    383     }
    384 
    385     // OnGUI is called for rendering and handling GUI events (Since v2.0)
    386     /// <summary>
    387     /// 渲染和处理GUI事件时调用。
    388     ///这意味着你的OnGUI程序将会在每一帧被调用。要得到更多的GUI事件的信息查阅Event手册。如果Monobehaviour的enabled属性设为false,OnGUI()将不会被调用。
    389     /// </summary>
    390     public void OnGUI()
    391     {
    392         if (GUI.Button(new Rect(10, 10, 150, 100), "I am a button"))
    393             print("You clicked the button!");
    394 
    395     }
    396 
    397     // Called on clients or servers when there is a problem connecting to the MasterServer (Since v2.0)
    398     /// <summary>
    399     /// 当连接主服务器出现问题时在客户端或服务器端调用.
    400     ///失败原因将作为 NetworkConnectionError 枚举传入.
    401     /// </summary>
    402     /// <param name="info"></param>
    403     public void OnFailedToConnectToMasterServer(NetworkConnectionError info)
    404     {
    405         Debug.Log("Could not connect to master server: " + info);
    406     }
    407 
    408     // Called on the client when a connection attempt fails for some reason (Since v2.0)
    409     /// <summary>
    410     /// 当一个连接因为某些原因失败时在客户端调用。
    411     ///失败原因将作为 NetworkConnectionError 枚举传入。
    412     /// </summary>
    413     /// <param name="error"></param>
    414     public void OnFailedToConnect(NetworkConnectionError error)
    415     {
    416         Debug.Log("Could not connect to server: " + error);
    417     }
    418 
    419     // This function is called when the object becomes enabled and active (Since v1.0)
    420     /// <summary>
    421     /// 当对象变为可用或激活状态时此函数被调用。
    422     /// </summary>
    423     public void OnEnable()
    424     {
    425 
    426     }
    427 
    428     // Implement this OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn (Since v1.0)
    429     /// <summary>
    430     /// 如果你想在物体被选中时绘制gizmos,执行这个函数。
    431     ///Gizmos只在物体被选择的时候绘制。Gizmos不能被点选,这可以使设置更容易。例如:一个爆炸脚本可以绘制一个球来显示爆炸半径
    432     /// </summary>
    433     public void OnDrawGizmosSelected()
    434     {
    435         float explosionRadius = 5.0F;
    436         // 被选中时显示爆炸半径.
    437         Gizmos.color = Color.white;
    438         Gizmos.DrawSphere(transform.position, explosionRadius);
    439 
    440     }
    441 
    442     // Implement this OnDrawGizmosSelected if you want to draw gizmos only if the object is selected (Since v1.0)
    443     /// <summary>
    444     /// 如果你想绘制可被点选的gizmos,执行这个函数。
    445     ///这允许你在场景中快速选择重要的物体。
    446     ///注意: OnDrawGizmos使用相对鼠标坐标。
    447     /// </summary>
    448     public void OnDrawGizmos()
    449     {
    450         //在物体的位置绘制一个灯泡图标
    451         Gizmos.DrawIcon(transform.position, "Light Gizmo.tiff");
    452     }
    453 
    454     // Called on the client when the connection was lost or you disconnected from the server (Since v2.0)
    455     /// <summary>
    456     /// 当失去连接或从服务器端断开时在客户端调用。
    457     /// </summary>
    458     /// <param name="info">网络中断</param>
    459     public void OnDisconnectedFromServer(NetworkDisconnection info)
    460     {
    461         Debug.Log("Disconnected from server: " + info);
    462     }
    463 
    464     // This function is called when the behaviour becomes disabled or inactive (Since v1.0)
    465     /// <summary>
    466     /// 当可编写脚本对象超出范围时调用这个函数。
    467     ///当物体被销毁也将被调用并且可以使用任何清除代码。当编译完成以后重新加载脚本时,OnDisable将被调用,随后脚本已经加载之后,OnEnable被调用。
    468     ///OnDisable不能作为一个协同程序。
    469     /// </summary>
    470     public void OnDisable()
    471     {
    472 
    473     }
    474 
    475     // This function is called when the MonoBehaviour will be destroyed (Since v3.2)
    476     /// <summary>
    477     /// 当MonoBehaviour将被销毁时,这个函数被调用。
    478     ///OnDestroy只会在预先已经被激活的游戏物体上被调用。
    479     ///OnDestroy不能用于协同程序。
    480     /// </summary>
    481     public void OnDestroy()
    482     {
    483 
    484     }
    485 
    486     // OnControllerColliderHit is called when the controller hits a collider while performing a Move (Since v2.0)
    487     /// <summary>
    488     /// 在移动的时,当controller碰撞到collider时OnControllerColliderHit被调用。
    489     /// 它可以用来在角色碰到物体时推开物体。
    490     /// </summary>
    491     /// <param name="hit">控制碰撞器碰撞</param>
    492     public void OnControllerColliderHit(ControllerColliderHit hit)
    493     {
    494         Rigidbody body = hit.collider.attachedRigidbody;
    495         // 没有刚体
    496         if (body == null || body.isKinematic)
    497             return;
    498         // 不推开我们身后的物体
    499         if (hit.moveDirection.y < -0.3F)
    500             return;
    501 
    502         Vector3 pushDir = new Vector3(hit.moveDirection.x, 0, hit.moveDirection.z);
    503         // 如果知道角色移动的速度,你可以用它乘以推动速度(pushPower)
    504         float pushPower = 2.0F;
    505         body.velocity = pushDir * pushPower;
    506 
    507     }
    508 
    509     // Called on the client when you have successfully connected to a server (Since v2.0)
    510     /// <summary>
    511     /// 当你成功连接到服务器时,在客户端调用。
    512     /// </summary>
    513     public void OnConnectedToServer()
    514     {
    515         Debug.Log("Connected to server");
    516     }
    517 
    518     // OnCollisionStay2D is called once per frame for every collider2D/rigidbody2D that is touching rigidbody2D/collider2D (2D physics only). (Since v4.3)
    519     public void OnCollisionStay2D(Collision2D coll)
    520     {
    521 
    522     }
    523 
    524     // OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider (Since v1.0)
    525     /// <summary>
    526     /// 当此collider/rigidbody触发另一个rigidbody/collider时,OnCollisionStay将会在每一帧被调用。
    527     /// 相对于OnTriggerExit,OnCollisionExit传递的是Collision类而不是Collider。
    528     /// Collision包含接触点,碰撞速度等细节。如果在函数中不使用碰撞信息,省略collisionInfo参数以避免不必要的运算.注意如果碰撞体附加了一个非动力学刚体,只发送碰撞事件。
    529     /// OnCollisionStay 可以被用作协同程序,在函数中调用yield语句。
    530     /// </summary>
    531     /// <param name="collisionInfo"></param>
    532     public void OnCollisionStay(Collision collisionInfo)
    533     {
    534         //eg:
    535         // 绘制所有接触点和法线
    536         foreach (ContactPoint contact in collisionInfo.contacts)
    537         {
    538             Debug.DrawRay(contact.point, contact.normal, Color.white);
    539         }
    540 
    541     }
    542 
    543     // OnCollisionExit2D is called when this collider2D/rigidbody2D has stopped touching another rigidbody2D/collider2D (2D physics only). (Since v4.3)
    544     //碰撞停止时候开始触发 仅用于2D物体
    545     public void OnCollisionExit2D(Collision2D coll)
    546     {
    547 
    548     }
    549 
    550     // OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider (Since v1.0)
    551     /// <summary>
    552     /// 此collider/rigidbody停止触发另一个rigidbody/collider时,OnCollisionExit将被调用。(即:碰撞停止)
    553     /// 相对于OnTriggerExit,OnCollisionExit传递的是Collision类而不是Collider。
    554     /// Collision包含接触点,碰撞速度等细节。如果在函数中不使用碰撞信息,省略collisionInfo参数以避免不必要的运算.注意如果碰撞体附加了一个非动力学刚体,只发送碰撞事件。
    555     /// OnCollisionExit 可以被用作协同程序,在函数中调用yield语句。
    556     /// </summary>
    557     /// <param name="collision"></param>
    558     public void OnCollisionExit(Collision collision)
    559     {
    560 
    561     }
    562 
    563     // OnCollisionEnter2D is called when this collider2D/rigidbody2D has begun touching another rigidbody2D/collider2D (2D physics only). (Since v4.3)
    564     //当两个物体开始碰撞到另一个物体时候触发 仅用于2D物体
    565     public void OnCollisionEnter2D(Collision2D coll)
    566     {
    567 
    568     }
    569 
    570     // OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider (Since v1.0)
    571     /// <summary>
    572     /// 当此collider/rigidbody触发另一个rigidbody/collider时,OnCollisionEnter将被调用。(即:碰撞开始)
    573     /// 相对于OnTriggerEnter,OnCollisionEnter传递的是Collision类而不是Collider。
    574     /// Collision包含接触点,碰撞速度等细节。如果在函数中不使用碰撞信息,省略collisionInfo参数以避免不必要的运算。注意如果碰撞体附加了一个非动力学刚体,只发送碰撞事件。
    575     /// OnCollisionEnter可以被用作协同程序,在函数中调用yield语句。
    576     /// </summary>
    577     /// <param name="collision">碰撞的碰撞器</param>
    578     public void OnCollisionEnter(Collision collision)
    579     {
    580         // 如果碰撞体有较大冲击则。。。。。
    581         //relativeVelocity:两个碰撞物体的相对线性速度(只读)。  magnitude:大小值
    582         if (collision.relativeVelocity.magnitude > 2)
    583         {
    584             //Dosomeing
    585         }
    586     }
    587 
    588     // OnBecameInvisible is called when the renderer is no longer visible by any camera (Since v1.0)
    589     /// <summary>
    590     /// 当renderer(渲染器)在任何相机上都不可见时调用OnBecameInvisible。
    591     /// 这个消息发送到所有附在渲染器的脚本上。 OnBecameVisible 和 OnBecameInvisible可以用于只需要在物体可见时才进行的计算。
    592     /// OnBecameVisible可以被用作协同程序,在函数中调用yield语句。当在编辑器中运行时,场景面板相机也会导致这个函数被调用。
    593     /// </summary>
    594     public void OnBecameInvisible()
    595     {
    596 
    597     }
    598 
    599     // OnBecameVisible is called when the renderer became visible by any camera (Since v1.0)
    600     /// <summary>
    601     /// 当renderer(渲染器)在任何相机上可见时调用OnBecameVisible。
    602     /// 这个消息发送到所有附在渲染器的脚本上。 OnBecameVisible 和 OnBecameInvisible可以用于只需要在物体可见时才进行的计算。
    603     /// OnBecameVisible可以被用作协同程序,在函数中调用yield语句。当在编辑器中运行时,场景面板相机也会导致这个函数被调用。
    604     /// </summary>
    605     public void OnBecameVisible()
    606     {
    607 
    608     }
    609 
    610 
    611 
    612     // If OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain (Since v3.5)
    613     public void OnAudioFilterRead(int channels, float[] data)
    614     {
    615 
    616     }
    617 
    618     // Sent to all game objects before the application is quit (Since v1.0)
    619     /// <summary>
    620     /// 在应用退出之前发送给所有的游戏物体。
    621     /// 当用户停止运行模式时在编辑器中调用。当web被关闭时在网页播放器中被调用。
    622     /// </summary>
    623     public void OnApplicationQuit()
    624     {
    625 
    626     }
    627 
    628     // Sent to all game objects when the player pauses (Since v1.0)
    629     /// <summary>
    630     /// 当玩家暂停时发送到所有的游戏物体。
    631     ///OnApplicationPause 可以作为协同程序,在函数中使用yield语句即可。
    632     /// </summary>
    633     /// <param name="pause"></param>
    634     public void OnApplicationPause(bool pause)
    635     {
    636 
    637     }
    638 
    639     // Sent to all game objects when the player gets or looses focus (Since v3.0)
    640     /// <summary>
    641     /// 当玩家获得或失去焦点时发送给所有游戏物体。
    642     ///OnApplicationFocus 可以作为协同程序,在函数中使用yield语句即可。
    643     /// </summary>
    644     /// <param name="focus"></param>
    645     public void OnApplicationFocus(bool focus)
    646     {
    647 
    648     }
    649 
    650     // This callback will be invoked at each frame after the state machines and the animations have been evaluated, but before OnAnimatorIK (Since v4.0)
    651     public void OnAnimatorMove()
    652     {
    653 
    654     }
    655 
    656     // Callback for setting up animation IK (inverse kinematics) (Since v4.0)
    657     public void OnAnimatorIK(int layerIndex)
    658     {
    659 
    660     }
    661 
    662     // LateUpdate is called every frame, if the Behaviour is enabled (Since v1.0)
    663     /// <summary>
    664     /// 当Behaviour启用时,其LateUpdate在每一帧被调用。
    665     /// LateUpdate是在所有Update函数调用后被调用。这可用于调整脚本执行顺序。例如:当物体在Update里移动时,跟随物体的相机可以在LateUpdate里实现。
    666     /// </summary>
    667     public void LateUpdate()
    668     {
    669 
    670     }
    671 
    672 
    673     /// <summary>
    674     /// This function is called every fixed framerate frame, if the MonoBehaviour is enabled (Since v1.0)
    675     /// 当MonoBehaviour启用时,其 FixedUpdate 在每一帧被调用。
    676     /// 每固定帧绘制时执行一次,和update不同的是FixedUpdate是渲染帧执行,
    677     /// 如果你的渲染效率低下的时候FixedUpdate调用次数就会跟着下降。FixedUpdate比较适用于物理引擎的计算,因为是跟每帧渲染有关。Update就比较适合做控制。
    678     /// 处理Rigidbody时,需要用FixedUpdate代替Update。例如:给刚体加一个作用力时,你必须应用作用力在FixedUpdate里的固定帧,而不是Update中的帧。(两者帧长不同)
    679     /// </summary>
    680     public void FixedUpdate()
    681     {
    682 
    683     }
    684 
    685 
    686     /***********************
    687      * 
    688      * 以下为MonoBehaviour下的方法
    689      */
    690 
    691 
    692     /// <summary>
    693     /// 取消这个MonoBehaviour上的所有调用。
    694     /// </summary>
    695     public void CancelInvokes()
    696     {
    697 
    698     }
    699 
    700     /// <summary>
    701     /// 在time秒调用methodName方法;简单说,根据时间调用指定方法名的方法
    702     /// 从第一次调用开始,每隔repeatRate时间调用一次.
    703     /// </summary>
    704     /// <param name="methodName">方法名(不用带括号)</param>
    705     /// <param name="time">第一次调用方法(methodName)的时间</param>
    706     /// <param name="repeatRate">每次循环调用方法(methodName)间隔时间</param>
    707     public void InvokeRepeating(string methodName, float time, float repeatRate)
    708     {
    709 
    710     }
    711     /// <summary>
    712     /// 在time秒调用methodName方法;简单说,根据时间调用指定方法名的方法.
    713     /// </summary>
    714     /// <param name="methodName">方法名(不用带括号)</param>
    715     /// <param name="time">第一次调用方法(methodName)的时间</param>
    716     public void Invoke(string methodName, float time)
    717     {
    718 
    719     }
    720     /// <summary>
    721     /// 某指定函数是否在等候调用。
    722     /// </summary>
    723     /// <param name="methodName">函数名</param>
    724     public void IsInvoking(string methodName)
    725     {
    726     }
    727     /// <summary>
    728     /// 停止这个动作中名为methodName的所有协同程序。
    729     ///请注意只有StartCoroutine使用一个字符串方法名时才能用StopCoroutine停用之.
    730     /// </summary>
    731     /// <param name="methodName">方法名</param>
    732     public void StopCoroutine(string methodName)
    733     {
    734     }
    735     /// <summary>
    736     /// 停止所有动作的协同程序。
    737     /// </summary>
    738     public void StopCoroutine()
    739     {
    740 
    741     }
    742     /// <summary>
    743     /// 开始协同程序。
    744     /// 一个协同程序在执行过程中,可以在任意位置使用yield语句。yield的返回值控制何时恢复协同程序向下执行。
    745     /// 协同程序在对象自有帧执行过程中堪称优秀。协同程序在性能上没有更多的开销。StartCoroutine函数是立刻返回的,但是yield可以延迟结果。直到协同程序执行完毕。
    746     ///用javascript不需要添加StartCoroutine,编译器将会替你完成.但是在C#下,你必须调用StartCoroutine。
    747     /// </summary>
    748     /// <param name="routine"></param>
    749     public void StartCoroutine(IEnumerator routine)
    750     {
    751 
    752     }
    753 }
  • 相关阅读:
    ECharts之柱状图 饼状图 折线图
    Vue自定义指令(directive)
    HDU 1231 最大连续子序列
    POJ 2533 Longest Ordered Subsequence
    HDU 1163 Eddy's digital Roots
    HDU 2317 Nasty Hacks
    HDU 2571 命运
    HDU 4224 Enumeration?
    HDU 1257 最少拦截系统
    HDU 2740 Root of the Problem
  • 原文地址:https://www.cnblogs.com/nsky/p/4137799.html
Copyright © 2011-2022 走看看