标签:
对于editorWindow,Time.deltaTime不起作用,所以需用下面方法对update进行计时:
public class myEditorWindow : EditorWindow
{
public float m_lastUpdateTime=0;
public myEditorWindow(){
wantsMouseMove = true;
}
public void Update(float dt){
//to do
}
private void Update()
{
float curTime = Time.realtimeSinceStartup;
m_lastUpdateTime = Mathf.Min (m_lastUpdateTime, curTime);//very important!!!
float dt=curTime-m_lastUpdateTime;
Update(dt);
m_lastUpdateTime = curTime;
}
}
其中m_lastUpdateTime = Mathf.Min (m_lastUpdateTime, curTime)一句非常重要,如果不加这句,将导致重大bug。
假设不加这句,试想假如当前curTime=1000.02,而m_lastUpdateTime=1000,则dt=curTime-m_lastUpdateTime=0.02,恰在此时,我们按下unity的play按钮,则下一次Update时curTime变为0,m_lastUpdateTime=1000.02,则dt=curTime-m_lastUpdateTime=-1000.02,是错的。
标签:
原文地址:http://www.cnblogs.com/wantnon/p/5123078.html