我是靠谱客的博主 魔幻饼干,这篇文章主要介绍Unity3D的Time类,现在分享给大家,希望可以做个参考。

Time类

主要还是参考官方文档

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using UnityEngine; using System.Collections; public class API02_Time : MonoBehaviour { private Transform sphere; public int maxCount = 10000; private float s = 0; // Use this for initialization void Start() { sphere = GameObject.Find("Sphere").transform; float t0 = Time.timeSinceLevelLoad; Method0(); float t1 = Time.timeSinceLevelLoad; Debug.Log(t1 - t0); float t2 = Time.timeSinceLevelLoad; Method1(); float t3 = Time.timeSinceLevelLoad; Debug.Log(t3 - t2); float t4 = Time.timeSinceLevelLoad; Method2(); float t5 = Time.timeSinceLevelLoad; Debug.Log(t5 - t4); } // Update is called once per frame void Update () { Debug.Log("Time.deltaTime: " + Time.deltaTime); //每一帧的时长,这不是固定值,随着不同机子性能不同而改变,总的在0.02左右 //Time.deltaTime = Time.unscaledDeltaTime * Time.timeScale; Debug.Log("Time.fixedDeltaTime: " + Time.fixedDeltaTime); //固定值,0.02(和Update()和FixedUpdate()一样) Debug.Log("Time.frameCount: " + Time.frameCount); //总帧数 Debug.Log("Time.realtimeSinceStartup: " + Time.realtimeSinceStartup); //不受TimeScale的影响,暂停的时间也算在里面 Debug.Log("Time.time: " + Time.time); //看系统带的说明吧没啥要说的 Debug.Log("Time.timeSinceLevelLoad " + Time.timeSinceLevelLoad); //字面意思,不包括暂停的时间 Time.timeScale = 1; //默认1(正常速度) 0:The World!! 99:Made in Heaven!! sphere.Translate(Vector3.forward * Time.deltaTime); } //使用Time.timeSinceLevelLoad测试性能 void Method0(){} void Method1() { for (int i = 1; i < maxCount; i++) { s += i; } } void Method2() { for (int i = 1; i < maxCount; i++) { s *= i; } } }

最后

以上就是魔幻饼干最近收集整理的关于Unity3D的Time类的全部内容,更多相关Unity3D内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部