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

搜索資源 注冊|登陸

等待

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

Unity3D游戲制作教程

Unity3D游戲制作教程

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

本系列包含Unity3D介紹、Unity3D導(dǎo)出人物、Unity3D導(dǎo)出場景、Unity3D導(dǎo)出動作、游戲測試最終完成一個簡單的游戲。是一套非常完整的Unity3D游戲制作教程。

關(guān)閉

Unity組件:Time Manager 時間管理器

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

lxiaoxiaoai111

普通會員

lxiaoxiaoai111

社區(qū)鼻祖:9級

關(guān)注3410人

  • 積分

    1617

  • 登陸

    1

  • 發(fā)帖

    2

  • 留言

    1

  • 作品

    1

間隔線


The Time Manager 時間管理器

Properties 屬性
  • Fixed Timestep 固定時間步
    A framerate-independent interval that dictates when physics calculations and FixedUpdate() events are performed.
    該時間間隔與幀速率無關(guān),用于物理計算和執(zhí)行FixedUpdate()事件
  • Maximum Allowed Timestep
    最大時間步
    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.
    該時間間隔與幀速率無關(guān),用于幀速率很低的糟糕情況。物理計算和FixedUpdate() 執(zhí)行不會超過指定的時間。
  • Time Scale
    時間比例
    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.
    時間流逝的速度?梢酝ㄟ^修改此值來模擬子彈時間的效果。1表示真實時間,0.5表示一半速度,2表示2倍速度。
Details 細(xì)節(jié)
Fixed Timestep 固定時間步

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.

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

以下是固定時步如何計算。在每一幀圖像繪制到屏幕之前,Unity將固定時間加上固定時步,然后執(zhí)行物理計算,直到它到達(dá)當(dāng)前時間。該過程與固定時步屬性直接相關(guān)。固定時步值越小,物理計算就越頻繁。將1除以固定時步可以得到每秒計算固定幀的數(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.

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

Maximum Allowed Timestep 最大時間步

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.

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

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.

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

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

最大時步對物理計算和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è)置為0.1時,如果幀速率低于1 /0.1=每秒10幀,物理計算和FixedUpdate()事件將會放慢。

Typical scenario 典型場景
  1. Let's assume Fixed Timestep is 0.01, which means that physx, fixedUpdate and animations should be processed every 10 ms.
    假設(shè)固定時步是0.01,這意味著PhysX,fixedUpdate和動畫 每10毫秒計算一次。
  2. When your frame time is ~33 ms then fixed loop is executed 3 times per visual frame on average.
    如果1幀的處理時間是33毫秒,那么固定時步循環(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ù),它取決于許多因素,包括場景的狀態(tài),操作系統(tǒng)的后臺程序等等。
  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,幀時間有時可以達(dá)到40-50毫秒,這意味著,固定循環(huán)會被執(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.
    如果固定時步循環(huán)中的計算任務(wù)十分繁重,physx,fixedUpdates事件和動畫導(dǎo)致幀時間延長了額外的10毫秒,又將會導(dǎo)致一次額外的固定時步計算。
  6. In some unlucky cases process described in 5. could extend to 10 and more times of processing fixed step loop.
    在某些糟糕的情況下, 5中描述的過程可能會導(dǎo)致10次以上的固定時步循環(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.
    這就是為什么我們要引入最大時步,它用來限制PhysX,fixedUpdates和動畫在一個圖形幀中運行的最大次數(shù)。如果你將最大時步設(shè)置為100毫秒,固定時步為10 ms,固定時步任務(wù)在一個圖形幀中最多執(zhí)行10次。因為固定時步循環(huán)次數(shù)的增加,有時侯小的性能問題可能會導(dǎo)致大的性能問題。如果把最大時步減少至30毫秒,固定時步循環(huán)的次數(shù)將限制為最多為3次,這意味著PhysX,fixedUpdate和動畫不會導(dǎo)致幀的處理時間大大延長。但限制也有一定的負(fù)面影響。當(dāng)性能出現(xiàn)問題時,你的動畫和物理模擬會稍稍變慢。
Hints 提示
  • Give the player control over time by changing Time Scale dynamically through scripting.
    通過腳本給玩家動態(tài)地調(diào)整時間比例以控制時間。
  • 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.
    如果游戲的物理計算量很大,或者在FixedUpdate()事件中消耗了大量時間,你可以設(shè)置最大時步為0.1。這可以阻止物理引擎將你的游戲幀率降到10幀/秒。

贊0 踩0

未知用戶

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

VIP

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

回頂部

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