zoukankan      html  css  js  c++  java
  • Unity3D Script Execution Order ——Question

       我 知道 Monobehaviour 上的 那些 event functions 是 在主线程 中 按 顺序调用的。这点从Manual/ExecutionOrder.html 上的 一张图就可以看出来。

       既然按 顺序 调用,那么 如果 比如update 在这一次 调用的 时候 执行 了 大量的运算 导致 主线程 被堵塞。是不是 意味着 这之后的 event funstion 也被堵塞了。

       测试一下:

     

     1 using UnityEngine;
     2 using System.Collections;
     3 
     4 public class mTest : MonoBehaviour {
     5 
     6     //public GameObject tmp;
     7 
     8     int index1 = 0;
     9     void FixedUpdate()
    10     {
    11         Debug.Log(" mTest  FixedUpdate " + Time.realtimeSinceStartup + " index1 : " + (index1++));
    12     }
    13 
    14 
    15     int index = 0;
    16 
    17     // Update is called once per frame
    18     void Update () {
    19 
    20         if (index == 0)
    21         {
    22             for (int i = 0; i < 1000; i++)
    23             {
    24                 Debug.Log("nothing");
    25             }
    26             //Destroy(tmp);
    27             //Debug.Log("test");
    28         }
    29         Debug.Log(" mTest  Update " + Time.realtimeSinceStartup + " index : " + (index++));
    30     }
    31 
    32     void LateUpdate()
    33     {
    34         Debug.Log(" mTest  LateUpdate " + Time.realtimeSinceStartup);
    35     }
    36 }

    上结果:

    结果很奇怪,的确是堵塞了,但是FixUpdate 在 第 2 帧 被 执行多次。无语了。

  • 相关阅读:
    android 混淆代码 -- 报错:can't find referenced class
    adb shell 删除删除指定文件夹和文件
    php GD库
    javascript的继承实现
    Mysql
    如何使用canvas画星星
    基于形态编程设计类
    算法
    腾讯web前端一面
    如何去克服害怕
  • 原文地址:https://www.cnblogs.com/chongxin/p/4115913.html
Copyright © 2011-2022 走看看