mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Merge pull request #23 from ALEXTANGXIAO/TEngine_v_3.0.0
TEngine v 3.0.0
This commit is contained in:
@@ -4,15 +4,6 @@ using UnityEngine;
|
|||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using TEngine;
|
using TEngine;
|
||||||
|
|
||||||
public enum EUIGroup
|
|
||||||
{
|
|
||||||
Root,
|
|
||||||
UI,
|
|
||||||
Dialog,
|
|
||||||
Tips,
|
|
||||||
System
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class UIExtension
|
public static class UIExtension
|
||||||
{
|
{
|
||||||
#region SetActive
|
#region SetActive
|
||||||
|
@@ -47,22 +47,18 @@ namespace TEngine
|
|||||||
/// <remarks>如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。</remarks>
|
/// <remarks>如果要获取的游戏框架模块不存在,则自动创建该游戏框架模块。</remarks>
|
||||||
public static T GetModule<T>() where T : class
|
public static T GetModule<T>() where T : class
|
||||||
{
|
{
|
||||||
Type interfaceType = typeof(T);
|
Type module = typeof(T);
|
||||||
if (!interfaceType.IsInterface)
|
|
||||||
|
if (module.FullName != null && !module.FullName.StartsWith("TEngine.", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
throw new GameFrameworkException(Utility.Text.Format("You must get module by interface, but '{0}' is not.", interfaceType.FullName));
|
throw new GameFrameworkException(Utility.Text.Format("You must get a Game Framework module, but '{0}' is not.", module.FullName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!interfaceType.FullName.StartsWith("TEngine.", StringComparison.Ordinal))
|
string moduleName = Utility.Text.Format("{0}.{1}", module.Namespace, module.Name.Substring(1));
|
||||||
{
|
|
||||||
throw new GameFrameworkException(Utility.Text.Format("You must get a Game Framework module, but '{0}' is not.", interfaceType.FullName));
|
|
||||||
}
|
|
||||||
|
|
||||||
string moduleName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name.Substring(1));
|
|
||||||
Type moduleType = Type.GetType(moduleName);
|
Type moduleType = Type.GetType(moduleName);
|
||||||
if (moduleType == null)
|
if (moduleType == null)
|
||||||
{
|
{
|
||||||
moduleName = Utility.Text.Format("{0}.{1}", interfaceType.Namespace, interfaceType.Name);
|
moduleName = Utility.Text.Format("{0}.{1}", module.Namespace, module.Name);
|
||||||
moduleType = Type.GetType(moduleName);
|
moduleType = Type.GetType(moduleName);
|
||||||
if (moduleType == null)
|
if (moduleType == null)
|
||||||
{
|
{
|
||||||
|
3
Assets/TEngine/Runtime/GameFramework/Timer.meta
Normal file
3
Assets/TEngine/Runtime/GameFramework/Timer.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 555d657d6bb444a983750fb61876af89
|
||||||
|
timeCreated: 1681822247
|
3
Assets/TEngine/Runtime/GameFramework/Timer/Timer.meta
Normal file
3
Assets/TEngine/Runtime/GameFramework/Timer/Timer.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9d644fbcf0a6413da6f4d0c54724266a
|
||||||
|
timeCreated: 1681822257
|
465
Assets/TEngine/Runtime/GameFramework/Timer/Timer/TimerManager.cs
Normal file
465
Assets/TEngine/Runtime/GameFramework/Timer/Timer/TimerManager.cs
Normal file
@@ -0,0 +1,465 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace TEngine
|
||||||
|
{
|
||||||
|
public delegate void TimerHandler(object[] args);
|
||||||
|
|
||||||
|
internal class TimerManager : GameFrameworkModule
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
public class Timer
|
||||||
|
{
|
||||||
|
public int timerId = 0;
|
||||||
|
public float curTime = 0;
|
||||||
|
public float time = 0;
|
||||||
|
public TimerHandler Handler;
|
||||||
|
public bool isLoop = false;
|
||||||
|
public bool isNeedRemove = false;
|
||||||
|
public bool isRunning = false;
|
||||||
|
public bool isUnscaled = false; //是否使用非缩放的时间
|
||||||
|
public object[] Args = null; //回调参数
|
||||||
|
}
|
||||||
|
|
||||||
|
private int _curTimerId = 0;
|
||||||
|
private readonly List<Timer> _timerList = new List<Timer>();
|
||||||
|
private readonly List<Timer> _unscaledTimerList = new List<Timer>();
|
||||||
|
private readonly List<int> _cacheRemoveTimers = new List<int>();
|
||||||
|
private readonly List<int> _cacheRemoveUnscaledTimers = new List<int>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加计时器
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="callback"></param>
|
||||||
|
/// <param name="time"></param>
|
||||||
|
/// <param name="isLoop"></param>
|
||||||
|
/// <param name="isUnscaled"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int AddTimer(TimerHandler callback, float time, bool isLoop = false, bool isUnscaled = false, params object[] args)
|
||||||
|
{
|
||||||
|
Timer timer = new Timer
|
||||||
|
{
|
||||||
|
timerId = ++_curTimerId,
|
||||||
|
curTime = time,
|
||||||
|
time = time,
|
||||||
|
Handler = callback,
|
||||||
|
isLoop = isLoop,
|
||||||
|
isUnscaled = isUnscaled,
|
||||||
|
Args = args,
|
||||||
|
isNeedRemove = false,
|
||||||
|
isRunning = true
|
||||||
|
};
|
||||||
|
|
||||||
|
InsertTimer(timer);
|
||||||
|
return timer.timerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InsertTimer(Timer timer)
|
||||||
|
{
|
||||||
|
bool isInsert = false;
|
||||||
|
if (timer.isUnscaled)
|
||||||
|
{
|
||||||
|
for (int i = 0, len = _unscaledTimerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
if (_unscaledTimerList[i].curTime > timer.curTime)
|
||||||
|
{
|
||||||
|
_unscaledTimerList.Insert(i, timer);
|
||||||
|
isInsert = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isInsert)
|
||||||
|
{
|
||||||
|
_unscaledTimerList.Add(timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0, len = _timerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
if (_timerList[i].curTime > timer.curTime)
|
||||||
|
{
|
||||||
|
_timerList.Insert(i, timer);
|
||||||
|
isInsert = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isInsert)
|
||||||
|
{
|
||||||
|
_timerList.Add(timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 暂停计时
|
||||||
|
/// </summary>
|
||||||
|
public void Stop(int timerId)
|
||||||
|
{
|
||||||
|
Timer timer = GetTimer(timerId);
|
||||||
|
if (timer != null) timer.isRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 恢复计时
|
||||||
|
/// </summary>
|
||||||
|
public void Resume(int timerId)
|
||||||
|
{
|
||||||
|
Timer timer = GetTimer(timerId);
|
||||||
|
if (timer != null) timer.isRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计时器是否在运行中
|
||||||
|
/// </summary>
|
||||||
|
public bool IsRunning(int timerId)
|
||||||
|
{
|
||||||
|
Timer timer = GetTimer(timerId);
|
||||||
|
return timer is { isRunning: true };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获得计时器剩余时间
|
||||||
|
/// </summary>
|
||||||
|
public float GetLeftTime(int timerId)
|
||||||
|
{
|
||||||
|
Timer timer = GetTimer(timerId);
|
||||||
|
if (timer == null) return 0;
|
||||||
|
return timer.curTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重置计时器,恢复到开始状态
|
||||||
|
/// </summary>
|
||||||
|
public void Restart(int timerId)
|
||||||
|
{
|
||||||
|
Timer timer = GetTimer(timerId);
|
||||||
|
if (timer != null)
|
||||||
|
{
|
||||||
|
timer.curTime = timer.time;
|
||||||
|
timer.isRunning = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重置计时器
|
||||||
|
/// </summary>
|
||||||
|
public void Reset(int timerId, TimerHandler callback, float time, bool isLoop = false, bool isUnscaled = false)
|
||||||
|
{
|
||||||
|
Timer timer = GetTimer(timerId);
|
||||||
|
if (timer != null)
|
||||||
|
{
|
||||||
|
timer.curTime = time;
|
||||||
|
timer.time = time;
|
||||||
|
timer.Handler = callback;
|
||||||
|
timer.isLoop = isLoop;
|
||||||
|
timer.isNeedRemove = false;
|
||||||
|
if (timer.isUnscaled != isUnscaled)
|
||||||
|
{
|
||||||
|
RemoveTimerImmediate(timerId);
|
||||||
|
|
||||||
|
timer.isUnscaled = isUnscaled;
|
||||||
|
InsertTimer(timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 重置计时器
|
||||||
|
/// </summary>
|
||||||
|
public void Reset(int timerId, float time, bool isLoop, bool isUnscaled)
|
||||||
|
{
|
||||||
|
Timer timer = GetTimer(timerId);
|
||||||
|
if (timer != null)
|
||||||
|
{
|
||||||
|
timer.curTime = time;
|
||||||
|
timer.time = time;
|
||||||
|
timer.isLoop = isLoop;
|
||||||
|
timer.isNeedRemove = false;
|
||||||
|
if (timer.isUnscaled != isUnscaled)
|
||||||
|
{
|
||||||
|
RemoveTimerImmediate(timerId);
|
||||||
|
|
||||||
|
timer.isUnscaled = isUnscaled;
|
||||||
|
InsertTimer(timer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 立即移除
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timerId"></param>
|
||||||
|
private void RemoveTimerImmediate(int timerId)
|
||||||
|
{
|
||||||
|
for (int i = 0, len = _timerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
if (_timerList[i].timerId == timerId)
|
||||||
|
{
|
||||||
|
_timerList.RemoveAt(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0, len = _unscaledTimerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
if (_unscaledTimerList[i].timerId == timerId)
|
||||||
|
{
|
||||||
|
_unscaledTimerList.RemoveAt(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 移除计时器
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timerId"></param>
|
||||||
|
public void RemoveTimer(int timerId)
|
||||||
|
{
|
||||||
|
for (int i = 0, len = _timerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
if (_timerList[i].timerId == timerId)
|
||||||
|
{
|
||||||
|
_timerList[i].isNeedRemove = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0, len = _unscaledTimerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
if (_unscaledTimerList[i].timerId == timerId)
|
||||||
|
{
|
||||||
|
_unscaledTimerList[i].isNeedRemove = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 移除所有计时器
|
||||||
|
/// </summary>
|
||||||
|
public void RemoveAllTimer()
|
||||||
|
{
|
||||||
|
_timerList.Clear();
|
||||||
|
_unscaledTimerList.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据TimerId获取计时器
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timerId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private Timer GetTimer(int timerId)
|
||||||
|
{
|
||||||
|
for (int i = 0, len = _timerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
if (_timerList[i].timerId == timerId)
|
||||||
|
{
|
||||||
|
return _timerList[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0, len = _unscaledTimerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
if (_unscaledTimerList[i].timerId == timerId)
|
||||||
|
{
|
||||||
|
return _unscaledTimerList[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoopCallInBadFrame()
|
||||||
|
{
|
||||||
|
bool isLoopCall = false;
|
||||||
|
for (int i = 0, len = _timerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
Timer timer = _timerList[i];
|
||||||
|
if (timer.isLoop && timer.curTime <= 0)
|
||||||
|
{
|
||||||
|
if (timer.Handler != null)
|
||||||
|
{
|
||||||
|
timer.Handler(timer.Args);
|
||||||
|
}
|
||||||
|
|
||||||
|
timer.curTime += timer.time;
|
||||||
|
if (timer.curTime <= 0)
|
||||||
|
{
|
||||||
|
isLoopCall = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoopCall)
|
||||||
|
{
|
||||||
|
LoopCallInBadFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoopCallUnscaledInBadFrame()
|
||||||
|
{
|
||||||
|
bool isLoopCall = false;
|
||||||
|
for (int i = 0, len = _unscaledTimerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
Timer timer = _unscaledTimerList[i];
|
||||||
|
if (timer.isLoop && timer.curTime <= 0)
|
||||||
|
{
|
||||||
|
if (timer.Handler != null)
|
||||||
|
{
|
||||||
|
timer.Handler(timer.Args);
|
||||||
|
}
|
||||||
|
|
||||||
|
timer.curTime += timer.time;
|
||||||
|
if (timer.curTime <= 0)
|
||||||
|
{
|
||||||
|
isLoopCall = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoopCall)
|
||||||
|
{
|
||||||
|
LoopCallUnscaledInBadFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateTimer(float elapseSeconds)
|
||||||
|
{
|
||||||
|
bool isLoopCall = false;
|
||||||
|
for (int i = 0, len = _timerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
Timer timer = _timerList[i];
|
||||||
|
if (timer.isNeedRemove)
|
||||||
|
{
|
||||||
|
_cacheRemoveTimers.Add(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!timer.isRunning) continue;
|
||||||
|
timer.curTime -= elapseSeconds;
|
||||||
|
if (timer.curTime <= 0)
|
||||||
|
{
|
||||||
|
if (timer.Handler != null)
|
||||||
|
{
|
||||||
|
timer.Handler(timer.Args);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timer.isLoop)
|
||||||
|
{
|
||||||
|
timer.curTime += timer.time;
|
||||||
|
if (timer.curTime <= 0)
|
||||||
|
{
|
||||||
|
isLoopCall = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_cacheRemoveTimers.Add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = _cacheRemoveTimers.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
_timerList.RemoveAt(_cacheRemoveTimers[i]);
|
||||||
|
_cacheRemoveTimers.RemoveAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoopCall)
|
||||||
|
{
|
||||||
|
LoopCallInBadFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void UpdateUnscaledTimer(float realElapseSeconds)
|
||||||
|
{
|
||||||
|
bool isLoopCall = false;
|
||||||
|
for (int i = 0, len = _unscaledTimerList.Count; i < len; i++)
|
||||||
|
{
|
||||||
|
Timer timer = _unscaledTimerList[i];
|
||||||
|
if (timer.isNeedRemove)
|
||||||
|
{
|
||||||
|
_cacheRemoveUnscaledTimers.Add(i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!timer.isRunning) continue;
|
||||||
|
timer.curTime -= realElapseSeconds;
|
||||||
|
if (timer.curTime <= 0)
|
||||||
|
{
|
||||||
|
if (timer.Handler != null)
|
||||||
|
{
|
||||||
|
timer.Handler(timer.Args);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timer.isLoop)
|
||||||
|
{
|
||||||
|
timer.curTime += timer.time;
|
||||||
|
if (timer.curTime <= 0)
|
||||||
|
{
|
||||||
|
isLoopCall = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_cacheRemoveUnscaledTimers.Add(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = _cacheRemoveUnscaledTimers.Count - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
_unscaledTimerList.RemoveAt(_cacheRemoveUnscaledTimers[i]);
|
||||||
|
_cacheRemoveUnscaledTimers.RemoveAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoopCall)
|
||||||
|
{
|
||||||
|
LoopCallUnscaledInBadFrame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly List<System.Timers.Timer> _ticker = new List<System.Timers.Timer>();
|
||||||
|
|
||||||
|
public System.Timers.Timer AddSystemTimer(Action<object, System.Timers.ElapsedEventArgs> callBack)
|
||||||
|
{
|
||||||
|
int interval = 1000;
|
||||||
|
var timerTick = new System.Timers.Timer(interval);
|
||||||
|
timerTick.AutoReset = true;
|
||||||
|
timerTick.Enabled = true;
|
||||||
|
timerTick.Elapsed += new System.Timers.ElapsedEventHandler(callBack);
|
||||||
|
|
||||||
|
_ticker.Add(timerTick);
|
||||||
|
|
||||||
|
return timerTick;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DestroySystemTimer()
|
||||||
|
{
|
||||||
|
foreach (var ticker in _ticker)
|
||||||
|
{
|
||||||
|
if (ticker != null)
|
||||||
|
{
|
||||||
|
ticker.Stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Update(float elapseSeconds, float realElapseSeconds)
|
||||||
|
{
|
||||||
|
UpdateTimer(elapseSeconds);
|
||||||
|
UpdateUnscaledTimer(realElapseSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal override void Shutdown()
|
||||||
|
{
|
||||||
|
DestroySystemTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 928cb27baf9022142915e745abe0bb95
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
115
Assets/TEngine/Runtime/GameFramework/Timer/Timer/TimerModule.cs
Normal file
115
Assets/TEngine/Runtime/GameFramework/Timer/Timer/TimerModule.cs
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace TEngine
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 计时器模块。
|
||||||
|
/// </summary>
|
||||||
|
[DisallowMultipleComponent]
|
||||||
|
public sealed partial class TimerModule : GameFrameworkModuleBase
|
||||||
|
{
|
||||||
|
private TimerManager _timerManager;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 游戏框架组件初始化。
|
||||||
|
/// </summary>
|
||||||
|
protected override void Awake()
|
||||||
|
{
|
||||||
|
base.Awake();
|
||||||
|
|
||||||
|
_timerManager = GameFrameworkEntry.GetModule<TimerManager>();
|
||||||
|
if (_timerManager == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("TimerMgr is invalid.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加计时器
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="callback"></param>
|
||||||
|
/// <param name="time"></param>
|
||||||
|
/// <param name="isLoop"></param>
|
||||||
|
/// <param name="isUnscaled"></param>
|
||||||
|
/// <param name="args"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int AddTimer(TimerHandler callback, float time, bool isLoop = false, bool isUnscaled = false, params object[] args)
|
||||||
|
{
|
||||||
|
if (_timerManager == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("TimerMgr is invalid.");
|
||||||
|
throw new GameFrameworkException("TimerMgr is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return _timerManager.AddTimer(callback, time, isLoop, isUnscaled, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 暂停计时
|
||||||
|
/// </summary>
|
||||||
|
public void Stop(int timerId)
|
||||||
|
{
|
||||||
|
if (_timerManager == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("TimerMgr is invalid.");
|
||||||
|
throw new GameFrameworkException("TimerMgr is invalid.");
|
||||||
|
}
|
||||||
|
_timerManager.Stop(timerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 移除计时器
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timerId"></param>
|
||||||
|
public void RemoveTimer(int timerId)
|
||||||
|
{
|
||||||
|
if (_timerManager == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("TimerMgr is invalid.");
|
||||||
|
throw new GameFrameworkException("TimerMgr is invalid.");
|
||||||
|
}
|
||||||
|
_timerManager.RemoveTimer(timerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 恢复计时
|
||||||
|
/// </summary>
|
||||||
|
public void Resume(int timerId)
|
||||||
|
{
|
||||||
|
if (_timerManager == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("TimerMgr is invalid.");
|
||||||
|
throw new GameFrameworkException("TimerMgr is invalid.");
|
||||||
|
}
|
||||||
|
_timerManager.Resume(timerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计时器是否在运行中
|
||||||
|
/// </summary>
|
||||||
|
public bool IsRunning(int timerId)
|
||||||
|
{
|
||||||
|
if (_timerManager == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("TimerMgr is invalid.");
|
||||||
|
throw new GameFrameworkException("TimerMgr is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return _timerManager.IsRunning(timerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 移除所有计时器
|
||||||
|
/// </summary>
|
||||||
|
public void RemoveAllTimer()
|
||||||
|
{
|
||||||
|
if (_timerManager == null)
|
||||||
|
{
|
||||||
|
Log.Fatal("TimerMgr is invalid.");
|
||||||
|
throw new GameFrameworkException("TimerMgr is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
_timerManager.RemoveAllTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 281867d7790648b4aa5342077ba3e5e1
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@@ -54,6 +54,11 @@ public class GameModule:MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static AudioModule Audio { get; private set; }
|
public static AudioModule Audio { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 计时器模块。
|
||||||
|
/// </summary>
|
||||||
|
public static TimerModule Timer { get; private set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -70,6 +75,7 @@ public class GameModule:MonoBehaviour
|
|||||||
Setting = Get<SettingModule>();
|
Setting = Get<SettingModule>();
|
||||||
UI = Get<UIModule>();
|
UI = Get<UIModule>();
|
||||||
Audio = Get<AudioModule>();
|
Audio = Get<AudioModule>();
|
||||||
|
Timer = Get<TimerModule>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InitCustomModules()
|
private static void InitCustomModules()
|
||||||
|
@@ -7,7 +7,6 @@
|
|||||||
"com.unity.2d.spriteshape": "5.3.0",
|
"com.unity.2d.spriteshape": "5.3.0",
|
||||||
"com.unity.2d.tilemap": "1.0.0",
|
"com.unity.2d.tilemap": "1.0.0",
|
||||||
"com.unity.collab-proxy": "1.15.15",
|
"com.unity.collab-proxy": "1.15.15",
|
||||||
"com.unity.device-simulator": "3.1.0-preview",
|
|
||||||
"com.unity.ide.rider": "2.0.7",
|
"com.unity.ide.rider": "2.0.7",
|
||||||
"com.unity.ide.visualstudio": "2.0.14",
|
"com.unity.ide.visualstudio": "2.0.14",
|
||||||
"com.unity.ide.vscode": "1.2.5",
|
"com.unity.ide.vscode": "1.2.5",
|
||||||
|
@@ -81,13 +81,6 @@
|
|||||||
},
|
},
|
||||||
"url": "https://packages.unity.cn"
|
"url": "https://packages.unity.cn"
|
||||||
},
|
},
|
||||||
"com.unity.device-simulator": {
|
|
||||||
"version": "3.1.0-preview",
|
|
||||||
"depth": 0,
|
|
||||||
"source": "registry",
|
|
||||||
"dependencies": {},
|
|
||||||
"url": "https://packages.unity.cn"
|
|
||||||
},
|
|
||||||
"com.unity.ext.nunit": {
|
"com.unity.ext.nunit": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
|
@@ -12,7 +12,7 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0}
|
m_Script: {fileID: 13964, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_EnablePreviewPackages: 1
|
m_EnablePreviewPackages: 0
|
||||||
m_EnablePackageDependencies: 0
|
m_EnablePackageDependencies: 0
|
||||||
m_AdvancedSettingsExpanded: 1
|
m_AdvancedSettingsExpanded: 1
|
||||||
m_ScopedRegistriesSettingsExpanded: 1
|
m_ScopedRegistriesSettingsExpanded: 1
|
||||||
|
Reference in New Issue
Block a user