Last active
August 29, 2015 14:19
-
-
Save suakig/62af434ace88b0bccaf3 to your computer and use it in GitHub Desktop.
_Time.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public static class _Time | |
{ | |
private static int iLastFrame = 0; | |
private static float fLastTime = 0.0f; | |
private static float fDeltaTime = 0.0f; | |
// 初期化:Start() で実行 | |
public static void StartDeltaTime() | |
{ | |
fLastTime = Time.realtimeSinceStartup; | |
iLastFrame = Time.frameCount; | |
} | |
// 更新:Update() で実行 | |
public static void UpdateDeltaTime() | |
{ | |
int iCurrentFrame = Time.frameCount; | |
if (iCurrentFrame != iLastFrame) | |
{ | |
float fCurrentTime = Time.realtimeSinceStartup; | |
fDeltaTime = fCurrentTime - fLastTime; | |
fLastTime = fCurrentTime; | |
iLastFrame = iCurrentFrame; | |
} | |
} | |
// 取得:Time.deltaTime を _Time.deltaTime に置き換えて使用する | |
public static float deltaTime | |
{ | |
get { | |
if (Time.timeScale == 0) return fDeltaTime; | |
else return Time.deltaTime; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment