版本:Unity 6(6000.0)
英语中文
  • C#

FrameData.deltaTime

建议变更

成功!

感谢你帮助我们改进 Unity 文档的质量。尽管我们无法接受所有提交,但我们确实阅读来自用户的所有变更建议,并会在适用情况下进行更新。

关闭

提交失败

由于某种原因导致无法提交你的变更建议。请在几分钟后重新尝试。感谢你花时间帮助我们改进 Unity 文档的质量。

关闭

取消

public float deltaTime;

说明

此帧与前一帧的间隔。该间隔未进行缩放,以秒为单位表示。

要为间隔设定时间比例,请将该间隔乘以 FrameData.effectiveSpeed

//Attach this script to a GameObject that has an Animator and set the Animator field.
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;

public class MyMonoBehaviour : MonoBehaviour { [SerializeField] private Animator m_Animator;

private PlayableGraph m_Graph; private void Awake() { m_Graph = PlayableGraph.Create(); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);

var scriptPlayable = ScriptPlayable<MyPlayableBehaviour>.Create(m_Graph);

// Sets game time's scale, as well as custom playable's speed. Time.timeScale = 10f; scriptPlayable.SetSpeed(0.5f);

var playableOutput = AnimationPlayableOutput.Create(m_Graph, "MyPlayableOutput", m_Animator); playableOutput.SetSourcePlayable(scriptPlayable, 0);

m_Graph.Play(); }

private void OnDestroy() { if (m_Graph.IsValid()) m_Graph.Destroy(); } }

public sealed class MyPlayableBehaviour : PlayableBehaviour { public override void PrepareFrame(Playable playable, FrameData info) { base.PrepareFrame(playable, info);

// info.deltaTime is not scaled, and so is 10 times smaller than Time.deltaTime // info.effectiveSpeed is equal to 5 (10 * 0.5). Time.timeScale is accounted for because we use DirectorUpdateMode.GameTime. // If we had used DirectorUpdateMode.UnscaledGameTime, info.effectiveSpeed would have been equal to 0.5. Debug.Log($"info.deltaTime = {info.deltaTime}, speed {info.effectiveSpeed} Time.deltaTime = {Time.deltaTime}"); } }