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 帧 被 执行多次。无语了。

  • 相关阅读:
    正则表达式学习1
    SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
    (转)DBUS基础知识
    WakeLock的使用
    观察者模式
    Notification的使用
    Head First 设计模式之入门
    (转)Android WebView总结
    书架也是一根筋
    PendingIntent分析
  • 原文地址:https://www.cnblogs.com/chongxin/p/4115913.html
Copyright © 2011-2022 走看看