2 回答

TA貢獻1829條經驗 獲得超7個贊
您將需要知道模擬的幀速率。如果 60 秒內采樣 1500 個樣本,則頻率大概為 25Hz。然后,您可以對每幀的兩個 MainFlow 值進行采樣,并在它們之間進行插值以產生平滑的輸出。
像這樣的東西:
float frequency = 25.0f;
float simulationTime = Time.time * frequency;
int firstFrameIndex = Mathf.Clamp(Mathf.FloorToInt(simulationTime), 0, MainFlow.length);
int secondFrameIndex = Mathf.Clamp(firstFrameIndex + 1, 0, MainFlow.length);
float fraction = simulationTime - firstFrameIndex;
float sample1 = (float)MainFlow[firstFrameIndex];
float sample2 = (float)MainFlow[secondFrameIndex];
float k = Mathf.Lerp(sample1, sample2, fraction) + 2.5f;
transform.localScale = new Vector3(k, k, k);

TA貢獻1803條經驗 獲得超6個贊
您當前的實現取決于幀速率,獲得的 fps 越高,模擬速度就越快。
相反,我會啟動一個協程來獲得更多控制權。假設 MainFlow 包含 1200 個樣本,總共 60 秒,這意味著采樣率為 20 Hz(樣本/秒)。因此,您應該每秒處理 20 個樣本,換句話說,每 1/20 秒處理 1 個樣本。
所以:
private float secondsPerSample;
private void Start()
{
? ? float sampleRate = MainFlow.Length / 60f;
? ? secondsPerSample = 1 / sampleRate;
? ? StartCoroutine(Process());
}
private IEnumerator Process()
{
? ? for (int i = 0; i < MainFlow.Length; i++)
? ? {
? ? ? ? float f = (float) MainFlow[i]; // value of current volume
? ? ? ? float k = f + 2.5f; // adding initial volume
? ? ? ? transform.localScale = new Vector3(k, k, k); i++;
? ? ? ? yield return new WaitForSeconds(secondsPerSample);
? ? }
? ? yield return Process();
}
- 2 回答
- 0 關注
- 188 瀏覽
添加回答
舉報