public override void PauseTimer(bool ispause = true) { _IsPause = ispause; if (ispause) { if (state == EventState.ES_Normal) { base.PauseTimer(ispause); _pauseTime = ScriptsTime.GetTimes(); TurnTimer(TimerTurnType.TT_Pause); } } else { if (state == EventState.ES_Pause) { float curTime = ScriptsTime.GetTimes(); float pt = curTime - _pauseTime; _startTime += pt; nextTime += pt; IsStatic = (nextTime - curTime) >= 5000; base.PauseTimer(ispause); TurnTimer(TimerTurnType.TT_UnPause); } } }
public TEvent() { handle = ++MaxHandle; stBody = FEngineManager.Engine; _startTime = ScriptsTime.GetTimes(); state = EventState.ES_Normal; }
public override void ResetData() { frequency = 0; _pauseTime = 0; base.ResetData(); if (_IsPause && state == EventState.ES_Normal) { _pauseTime = ScriptsTime.GetTimes(); state = EventState.ES_Pause; } }
private static int DEGREE = 10;//精度DEGREE毫秒 public TimerMachine() { mTimerRunTime = ScriptsTime.GetTimes(); mStartTime = mTimerRunTime; }
private float _pauseTime = 0; //暂停时间 internal TimerEvent SetNextTime(float waitTime) { nextTime = ScriptsTime.GetTimes() + waitTime * 1000; IsStatic = false; return(this); }
public virtual void ResetData() { _startTime = ScriptsTime.GetTimes(); state = EventState.ES_Normal; }
public void Update() { mTempDeltaTime = ScriptsTime.GetTimes(); mDeltaTime = (mTempDeltaTime - mTimerRunTime) / 1000.0f; mTimerRunTime = mTempDeltaTime; //定时器转换 if (mTurnEvents.Count != 0) { for (int i = 0; i < mTurnEvents.Count; i++) { var timer = mTurnEvents[i]; if (timer.mTurnType == TimerEvent.TimerTurnType.TT_DynamicTurn) { PustTimer(timer); } else { switch (timer.mTurnType) { case TimerEvent.TimerTurnType.TT_Pause: PustTimer(timer); break; case TimerEvent.TimerTurnType.TT_UnPause: PustTimer(timer); break; case TimerEvent.TimerTurnType.TT_Reset: timer.ResetData(); PustTimer(timer); break; case TimerEvent.TimerTurnType.TT_Delete: ForceFree(timer, true); break; } } } mTurnEvents.Clear(); } //动态定时器 if (mDynamicTimerEvents.Count != 0) { for (int i = mDynamicTimerEvents.Count - 1; i >= 0; i--) { var timer = mDynamicTimerEvents[i]; TimerState result = _PlayTimer(timer); if (result == TimerState.T_Carry) { if (timer.IsStatic) { PushTurnEvent(TimerEvent.TimerTurnType.TT_DynamicTurn, timer); } } else if (result == TimerState.T_Turn) { ForceFree(timer, false); } } } int tick = (int)((mTempDeltaTime - mStartTime) / DEGREE);//DEGREE毫秒的精度 mLastTick = tick; }