游戏中时间管理器
来源:互联网 发布:淘宝樊小林捕鼠 编辑:程序博客网 时间:2024/05/20 13:07
摘自我司主程周峰之 gametimer.cs
using System;
using System.IO;
using System.Threading;
using UnityEngine;
using System.Collections;
public class GameTimer : MonoBehaviour, PauseAbleBase
{
protected static GameTimer _inst = null;
public static GameTimer Instance
{
get
{
if (_inst == null)
{
_inst = FindObjectOfType<GameTimer>();
if (_inst == null)
{
var obj = new GameObject("__GameTimer");
_inst = obj.AddComponent<GameTimer>();
}
}
return _inst;
}
}
void OnEnable() { _inst = this; }
void OnDisable() { _inst = null; }
// Update is called once per frame
void Update ()
{
if (!IsPaused)
TimeFromSceneLoad += Time.deltaTime;
}
public float DeltaTime
{
get
{
if (! IsPaused)
{
return Time.deltaTime;
}
else
{
return 0;
}
}
}
private float TimeFromSceneLoad = 0f;
private bool IsPaused = false;
public bool Pause
{
get { return IsPaused; }
}
public void OnPause()
{
// pause audio
AudioManager.Instance.OnPause();
EnemyController.Instance.PauseGame();
if (BossBase.Instance)
{
BossBase.Instance.WhenPause();
}
if (UIBattleManager.Instance)
{
UIBattleManager.Instance.PauseBuff();
}
IsPaused = true;
}
public void OnResume()
{
// resume audio
AudioManager.Instance.OnResume();
IsPaused = false;
EnemyController.Instance.ResumeGame();
if (BossBase.Instance)
{
BossBase.Instance.WhenResume();
}
if (UIBattleManager.Instance)
{
UIBattleManager.Instance.ResumeBuff();
}
}
public float TimeFromStart
{
get { return TimeFromSceneLoad; }
}
/// <summary>
/// 获得格林尼治时间ticks
/// </summary>
public static long SystemNowTimeStamp
{
get { return DateTime.Now.ToFileTime(); }
}
public static void GetNowTimeFormat(out int year,out int month, out int day)
{
GetTimeFormat(out year, out month, out day, SystemNowTimeStamp);
}
public static void GetTimeFormat(out int year, out int month,out int day, long timeStamp)
{
var date = DateTime.FromFileTime(timeStamp);
year = date.Year;
month = date.Month;
day = date.Day;
}
public static bool IsSameDay(long timestamp1, long timestamp2)
{
int year, month, day, lastYear, lastMonth, lastDay;
GetTimeFormat(out lastYear, out lastMonth, out lastDay, timestamp1);
GetTimeFormat(out year, out month, out day, timestamp2);
if (year != lastYear || month != lastMonth || day != lastDay)
{
return false;
}
else
{
return true;
}
}
public static int TimeSpanMinites(long after, long before)
{
TimeSpan span = new TimeSpan(after - before);
//span.TotalMinutes
return Mathf.FloorToInt((float)span.TotalMinutes);
}
public static double TimeSpanSeconds(long after, long before)
{
TimeSpan span = new TimeSpan(after-before);
return ( span.TotalSeconds);
}
}
- 游戏中时间管理器
- 游戏管理器
- (转)[Windows]在Win7游戏管理器中添加游戏
- 时间管理器
- 游戏.消息管理器
- 游戏.状态管理器
- 游戏管理器(1)
- 游戏管理器(2)
- 时间管理器,时钟
- Time Manager 时间管理器
- 游戏中,常见时间处理函数
- 游戏中冷却时间的管理
- 在游戏中记录游戏运行的时间
- 游戏及学习控制管理器
- 巧用Windows 7游戏管理器
- 巧用Windows 7游戏管理器
- 游戏对象数据存储管理器
- 电脑中设备管理器->声音、视频和游戏控制器突然不见了——解决方法
- 2014-2015 HHUC 跨年二分专题 解题报告
- 秀色书文软件 发布
- UVA 152-Tree's a Crowd(暴力求解三维坐标求最短距离)
- jvm的happens-before原则
- Leetcode -- Merge k Sorted Lists
- 游戏中时间管理器
- C++标准库---transform()
- android AR项目总结
- Android判断当前Service是否是重启的Servcie
- 重构.改善既有代码的设计
- day05_java数组的操作
- 第一天java
- Java中类的构造器
- js中的拖拽——两种