朱峰社區(qū)首頁(yè) 朱峰社區(qū)

搜索資源 注冊(cè)|登陸

等待

返回 展開菜單
按功能 按軟件

unity3d視頻教程

unity3d視頻教程

包含11節(jié)視頻教程

從零基礎(chǔ)學(xué)習(xí)unity3d游戲引擎,簡(jiǎn)單易學(xué)的視頻教程,讓你快速掌握unity3d,并喜歡上游戲開發(fā)的樂趣。

關(guān)閉

Unity組件:Time Manager 時(shí)間管理器

關(guān)注:1123 留言:0 樓主:lxiaoxiaoai111 發(fā)帖時(shí)間:15年11月16日

lxiaoxiaoai111

普通會(huì)員

lxiaoxiaoai111

社區(qū)鼻祖:9級(jí)

關(guān)注3861人

  • 積分

    1617

  • 登陸

    1

  • 發(fā)帖

    2

  • 留言

    1

  • 作品

    1

間隔線


The Time Manager 時(shí)間管理器

Properties 屬性
  • Fixed Timestep 固定時(shí)間步
    A framerate-independent interval that dictates when physics calculations and FixedUpdate() events are performed.
    該時(shí)間間隔與幀速率無(wú)關(guān),用于物理計(jì)算和執(zhí)行FixedUpdate()事件
  • Maximum Allowed Timestep
    最大時(shí)間步
    A framerate-independent interval that caps the worst case scenario when frame-rate is low. Physics calculations and FixedUpdate() events will not be performed for longer time than specified.
    該時(shí)間間隔與幀速率無(wú)關(guān),用于幀速率很低的糟糕情況。物理計(jì)算和FixedUpdate() 執(zhí)行不會(huì)超過指定的時(shí)間。
  • Time Scale
    時(shí)間比例
    The speed at which time progress. Change this value to simulate bullet-time effects. A value of 1 means real-time. A value of .5 means half speed; a value of 2 is double speed.
    時(shí)間流逝的速度?梢酝ㄟ^修改此值來(lái)模擬子彈時(shí)間的效果。1表示真實(shí)時(shí)間,0.5表示一半速度,2表示2倍速度。
Details 細(xì)節(jié)
Fixed Timestep 固定時(shí)間步

Fixed time stepping is very important for stable physics simulation. Not all computers are made equal, and different hardware configurations will run Unity games with varying performance. Therefore, physics must be calculated independently of the game's frame rate. Physics calculations like collision detection and Rigidbody movement are performed in discrete fixed time steps that are not dependent on frame rate. This makes the simulation more consistent across different computers or when changes in the frame rate occur. For example, the frame rate can drop due to an appearance of many game onscreen, or because the user launched another application in the background.

固定時(shí)步對(duì)穩(wěn)定的物理模擬非常重要。不同計(jì)算機(jī)的硬件配置在運(yùn)行unity的游戲時(shí)有不同的性能表現(xiàn)。因此物理模擬必須獨(dú)立于幀速率進(jìn)行計(jì)算。碰撞檢測(cè)和剛體運(yùn)動(dòng)等物理計(jì)算在離散的固定時(shí)步中執(zhí)行,與幀速率無(wú)關(guān)。這使得物理模擬在不同的計(jì)算機(jī)上或幀速率發(fā)生變化時(shí)是一致的。例如,游戲屏幕內(nèi)容的變化和用戶在后臺(tái)執(zhí)行程序都會(huì)導(dǎo)致幀速率下降。

Here's how the fixed time step is calculated. Before every frame is drawn onscreen, Unity advances the fixed time by fixed delta time and performs physics calculations until it reaches the current time. This directly correlates to the Fixed Timestep property. The smaller the value of Fixed Timestep, the more frequently physics will be calculated. The number of Fixed frames per second can be calculated by dividing 1 by Fixed Timestep. Therefore, 1 / 0.02 = 50 fixed frames per second and 1 / 0.05 = 20 fixed frames per second.

以下是固定時(shí)步如何計(jì)算。在每一幀圖像繪制到屏幕之前,Unity將固定時(shí)間加上固定時(shí)步,然后執(zhí)行物理計(jì)算,直到它到達(dá)當(dāng)前時(shí)間。該過程與固定時(shí)步屬性直接相關(guān)。固定時(shí)步值越小,物理計(jì)算就越頻繁。將1除以固定時(shí)步可以得到每秒計(jì)算固定幀的數(shù)量。所以,1 /0.02=50固定幀每秒,1 /0.05=20固定幀每秒。

Simply put, a smaller fixed update value leads to more accurate physics simulation but is heavier on the CPU.

簡(jiǎn)而言之,一個(gè)較小的固定更新值可以得到更準(zhǔn)確的物理模擬,但CPU的負(fù)擔(dān)會(huì)加重。

Maximum Allowed Timestep 最大時(shí)間步

Fixed time stepping ensures stable physics simulation. However it can cause negative impact on performance if game is heavy on physics and is already running slow or occasionally dips to low frame rate. Longer the frame takes to process - more fixed update steps will have to be executed for the next frame. This results in performance degradation. To prevent such scenario Unity iOS introduced Maximum Allowed Timestep which ensures that physics calculations will not run longer than specified threshold.

固定時(shí)步可以確保穩(wěn)定的物理模擬。然而,如果游戲的物理計(jì)算過多導(dǎo)致運(yùn)行緩慢或者幀速率間或降低,會(huì)造成負(fù)面影響。幀的處理時(shí)間越長(zhǎng),要執(zhí)行的固定時(shí)步更新次數(shù)就越多,這會(huì)導(dǎo)致性能下降。為了防止這種情況,Unity iOS通過引入最大時(shí)步來(lái)確保物理計(jì)算不會(huì)超過指定的閾值。

If frame takes longer to process than time specified in Maximum Allowed Timestep, then physics will "pretend" that frame took only Maximum Allowed Timestep seconds. In other words if frame rate drops below some threshold, then rigid bodies will slow down a bit allowing CPU to catch up.

如果幀的處理時(shí)間超過了最大時(shí)步,物理引擎會(huì)"假裝"該幀只消耗了最大時(shí)步的時(shí)間。換句話說,如果幀速率下降到低于某個(gè)閾值,剛體將會(huì)放慢一點(diǎn)讓CPU趕上。

Maximum Allowed Timestep affects both physics calculation and FixedUpdate() events.

最大時(shí)步對(duì)物理計(jì)算和FixedUpdate()事件都有影響。

Maximum Allowed Timestep is specified in seconds as Fixed Timestep. Therefore setting 0.1 will make physics and FixedUpdate() events to slow down, if frame rate dips below 1 / 0.1 = 10 frames per second.

最大時(shí)步的單位是秒。因此設(shè)置為0.1時(shí),如果幀速率低于1 /0.1=每秒10幀,物理計(jì)算和FixedUpdate()事件將會(huì)放慢。

Typical scenario 典型場(chǎng)景
  1. Let's assume Fixed Timestep is 0.01, which means that physx, fixedUpdate and animations should be processed every 10 ms.
    假設(shè)固定時(shí)步是0.01,這意味著PhysX,fixedUpdate和動(dòng)畫 每10毫秒計(jì)算一次。
  2. When your frame time is ~33 ms then fixed loop is executed 3 times per visual frame on average.
    如果1幀的處理時(shí)間是33毫秒,那么固定時(shí)步循環(huán)將在每幀執(zhí)行3次。
  3. But frametime isn't fixed constant and depends on many factors including your scene state, OS background taks, etc.
    但每幀的處理時(shí)間不是固定不變的常數(shù),它取決于許多因素,包括場(chǎng)景的狀態(tài),操作系統(tǒng)的后臺(tái)程序等等。
  4. Because of 3. reasons frametime sometimes can reach 40-50 ms, which means that fixed step loop will be executed 4-5 times.
    由于原因3,幀時(shí)間有時(shí)可以達(dá)到40-50毫秒,這意味著,固定循環(huán)會(huì)被執(zhí)行4-5次。
  5. When your fixed timestep tasks are pretty heavy then time spent on physx, fixedUpdates and animations extend your frametime by another 10 ms, which means one more additional iteration of all these fixed timestep tasks.
    如果固定時(shí)步循環(huán)中的計(jì)算任務(wù)十分繁重,physx,fixedUpdates事件和動(dòng)畫導(dǎo)致幀時(shí)間延長(zhǎng)了額外的10毫秒,又將會(huì)導(dǎo)致一次額外的固定時(shí)步計(jì)算。
  6. In some unlucky cases process described in 5. could extend to 10 and more times of processing fixed step loop.
    在某些糟糕的情況下, 5中描述的過程可能會(huì)導(dǎo)致10次以上的固定時(shí)步循環(huán)。
  7. That's why Maximum Allowed Timestep was introduced, it is the method to limit how much times physx, fixedUpdates and animations can be processed during single visual frame. If you have Maximum Allowed Timestep set to 100 ms and your Fixed Timestep is 10 ms, then for fixed step tasks will be executed up to 10 times per visual frame. So sometimes small performance hitch could trigger big performance hitch because of increased fixed timestep iteration count. By decreasing Maximum Allowed Timestep to 30 ms, you are limiting max fixed step iteration count to 3 and this means that your physx, fixedUpdate and animation won't blow your frametime up very much, but there is some negative effect of this limiting. Your animations and physics will slow down a bit when performance hitch occurs.
    這就是為什么我們要引入最大時(shí)步,它用來(lái)限制PhysX,fixedUpdates和動(dòng)畫在一個(gè)圖形幀中運(yùn)行的最大次數(shù)。如果你將最大時(shí)步設(shè)置為100毫秒,固定時(shí)步為10 ms,固定時(shí)步任務(wù)在一個(gè)圖形幀中最多執(zhí)行10次。因?yàn)楣潭〞r(shí)步循環(huán)次數(shù)的增加,有時(shí)侯小的性能問題可能會(huì)導(dǎo)致大的性能問題。如果把最大時(shí)步減少至30毫秒,固定時(shí)步循環(huán)的次數(shù)將限制為最多為3次,這意味著PhysX,fixedUpdate和動(dòng)畫不會(huì)導(dǎo)致幀的處理時(shí)間大大延長(zhǎng)。但限制也有一定的負(fù)面影響。當(dāng)性能出現(xiàn)問題時(shí),你的動(dòng)畫和物理模擬會(huì)稍稍變慢。
Hints 提示
  • Give the player control over time by changing Time Scale dynamically through scripting.
    通過腳本給玩家動(dòng)態(tài)地調(diào)整時(shí)間比例以控制時(shí)間。
  • If your game is physics heavy or spends significant amount of time in FixedUpdate() events, then set Maximum Allowed Timestep to 0.1. This will prevent physics from driving your game below 10 frames per second.
    如果游戲的物理計(jì)算量很大,或者在FixedUpdate()事件中消耗了大量時(shí)間,你可以設(shè)置最大時(shí)步為0.1。這可以阻止物理引擎將你的游戲幀率降到10幀/秒。

贊0 踩0

未知用戶

2005-2025 朱峰社區(qū) 版權(quán)所有 遼ICP備2021001865號(hào)-1
2005-2025 ZhuFeng Community All Rights Reserved

VIP

朱峰社區(qū)微信公眾號(hào)

回頂部

1.復(fù)制文本發(fā)給您的QQ好友或群、微信等;好友點(diǎn)擊鏈接以后,轉(zhuǎn)發(fā)就成功了。 2.如朋友點(diǎn)擊您的鏈接,您需要需刷新一下才行;同一個(gè)好友僅能點(diǎn)擊一次。
購(gòu)買VIP,觀看所有收費(fèi)教程!