Time類の中の「大哥大」(⊙o⊙)

1706 ワード

Time.deltaTimeのテスト:
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;

    public class timeTest : MonoBehaviour {
        public Transform cube;
     // Use this for initialization
     void Start () {
    }
      // Update is called once per frame
    void Update () {
         //Vector3.forward , 
          cube.Translate(Vector3.forward);
        // ( , )
          cube.Translate(Vector3.forward / 50f);
        // ( , )
          cube.Translate(Vector3.forward * Time.deltaTime );
        //Time.timeScale  , 1
        //timeScale deltaTime 
        // <1,deltaTime ; >1,deltaTime 
        //Time.deltaTime = Time.deltaTime * Time.timeScale
          Time.timeScale = 0.5f;
    }
    }

Time.realtimeSinceStartupは、メソッド実行前後のフレーム実行回数を取得できるため、減算すると対応する時間が得られるメソッドのパフォーマンスをテストするためによく使用されます.
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class timeTest : MonoBehaviour {

    public int runCount = 1000000;
    // Use this for initialization
    void Start () {
    float time1 = Time.realtimeSinceStartup;
    for (int i = 0; i < runCount; i++)
    {
        Method1();

    }
    float time2 = Time.realtimeSinceStartup;
    Debug.Log(time2 - time1);

    float time3 = Time.realtimeSinceStartup;
    for (int i = 0; i < runCount; i++)
    {
        Method2();

    }
    float time4 = Time.realtimeSinceStartup;
    Debug.Log(time4 - time3);

    }

    // Update is called once per frame
    void Update () {

    }

     void Method1() {
                int i = 1 + 2;
     }

     void Method2() {
                int j = 1 * 2;
     }
     }