Unity 对运行顺序,整体架构的理解,初学

来源:互联网 发布:淘宝开店不知道卖什么 编辑:程序博客网 时间:2024/05/07 03:19
  • 为一个场景对象添加上三个脚本,在场景开始运行时,脚本中的Start方法将会按照脚本添加的顺序来依次运行,而Update方法却是完全相反
    比如:有A1、A2、A3三个脚本,它们的添加顺序是A1、A3、A2,那么在场景运行时,程序运行顺序是A1.Start()、A3.Start()、 A2.Start()、A2.Update()、A3.Update()、A1.Update()……,即使A1.Start()或A2.Update ()运算时间超过其它的方法,那么其它的方法也会等待其运行完成后才会开始运行之……

    下面是三个脚本文件的例程:

    jxxh01.cs
    [csharp] view plaincopyprint?
    1. using UnityEngine;  
    2. using System.Collections;  
    3.   
    4. public class jxxh01 : MonoBehaviour  
    5. {  
    6.   
    7. // Use this for initialization  
    8. void Start()  
    9. {  
    10.   
    11. for (int temp02 = 0; temp02 < 5; temp02++)  
    12. {  
    13. for (int temp01 = 0; temp01 < 5; temp01++)  
    14. {  
    15. int a01 = 0;  
    16. for (int temp = 0; temp < 50000; temp++)  
    17. {  
    18. a01++;  
    19.   
    20. a = a01;  
    21. }  
    22. a01 = 0;  
    23. }  
    24. }  
    25.   
    26.   
    27.   
    28. print(Time.time + " This is jxxh01 : " + a);  
    29.   
    30. }  
    31.   
    32. public int ForValue=10000;  
    33.   
    34. int a = 0;  
    35.   
    36. // Update is called once per frame  
    37. void Update () {  
    38.   
    39.   
    40. for (int temp = 0; temp < ForValue; temp++) { a = temp; }  
    41. print(Time.time + " This is jxxh01 : " + a);  
    42.   
    43. }  
    44. }  



    jxxh02.cs
    [csharp] view plaincopyprint?
    1. using UnityEngine;  
    2.   
    3. using System.Collections;  
    4.   
    5.   
    6.   
    7. public class jxxh02 : MonoBehaviour  
    8.   
    9. {  
    10.   
    11.   
    12.   
    13. // Use this for initialization  
    14.   
    15. void Start()  
    16.   
    17. {  
    18.   
    19.   
    20.   
    21. for (int temp = 0; temp < 10000; temp++)  
    22.   
    23. {  
    24.   
    25. a++;  
    26.   
    27. }  
    28.   
    29. print(Time.time + " This is jxxh02 : " + a);  
    30.   
    31.   
    32.   
    33. }  
    34.   
    35.   
    36.   
    37. public int ForValue = 100;  
    38.   
    39.   
    40.   
    41. int a = 0;  
    42.   
    43.   
    44.   
    45. // Update is called once per frame  
    46.   
    47. void Update () {  
    48.   
    49.   
    50.   
    51.   
    52.   
    53. print(Time.time + " This is jxxh02 : " + a);  
    54.   
    55.   
    56.   
    57. }  
    58.   
    59. }  



    jxxh03.cs
    [csharp] view plaincopyprint?
    1. using UnityEngine;  
    2.   
    3. using System.Collections;  
    4.   
    5.   
    6.   
    7. public class jxxh03 : MonoBehaviour  
    8.   
    9. {  
    10.   
    11.   
    12.   
    13. // Use this for initialization  
    14.   
    15. void Start()  
    16.   
    17. {  
    18.   
    19.   
    20.   
    21. for (int temp = 0; temp < 10000; temp++)  
    22.   
    23. {  
    24.   
    25. a++;  
    26.   
    27. }  
    28.   
    29. print(Time.time + " This is jxxh03 : " + a);  
    30.   
    31.   
    32.   
    33. }  
    34.   
    35.   
    36.   
    37. public int ForValue = 100;  
    38.   
    39.   
    40.   
    41. int a = 0;  
    42.   
    43.   
    44.   
    45. // Update is called once per frame  
    46.   
    47. void Update () {  
    48.   
    49.   
    50.   
    51.   
    52.   
    53. print(Time.time + " This is jxxh03 : " + a);  
    54.   
    55.   
    56.   
    57. }  
    58.   
    59. }            
0 0
原创粉丝点击