using UnityEngine;
using System.Collections;
namespace YLBattle
{
///
/// 时间比例校正.
///
public class TimeScale : MonoBehaviour
{
bool isPause;
float curTime;
private static TimeScale mInstance;
///
/// 暂停时间周期 引用计数
///
float mPauseTimeCount;
///
/// 旧的时间
///
float mOldTime;
///
/// 获取单键
///
/// 单键实例
public static TimeScale Instance()
{
if (mInstance == null)
{
GameObject obj = new GameObject("TimeScale");
mInstance = obj.AddComponent();
}
return mInstance;
}
///
/// 更新
///
void Update()
{
if (isPause)
{
return;
}
//float targetFrameRate = (float)Application.targetFrameRate;
//if (targetFrameRate > 30)
//{
// Time.timeScale = 1;
//}
//else if (targetFrameRate <= 12)
//{
// Time.timeScale = .4f;
//}
//else
//{
//Time.timeScale = targetFrameRate / 30;
//}
}
///
/// 继续重载
///
public void Pause()
{
mOldTime = Time.realtimeSinceStartup;
isPause = true;
Time.timeScale = 0;
mPauseTimeCount += 1;
}
///
/// 继续 播放
///
public void Play()
{
mPauseTimeCount -= 1;
if (mPauseTimeCount <= 0)
{
isPause = false;
Time.timeScale = 1;
mPauseTimeCount = 0;
}
}
///
/// 获取isPause
///
///
public bool GetPause()
{
return isPause;
}
///
/// 强制取消暂停
///
///
public void PauseOver()
{
isPause = false;
Time.timeScale = 1;
this.mPauseTimeCount = 0;
}
}
}