/** 添加timeEx */ private int addTimeEx(TimeExecuteData tData) { int index = _timeExIndexMaker.get(); tData.index = index; _timeExDic.put(index, tData); return(index); }
/// <summary> /// 暂停时间ex /// </summary> public void pauseTimeEx(int index, bool value) { TimeExecuteData tData = _timeExDic.get(index); if (tData == null) { return; } tData.pause = value; }
/// <summary> /// 重置timeEx /// </summary> public void resetTimeEx(int index, int delay) { TimeExecuteData tData = _timeExDic.get(index); if (tData == null) { return; } tData.time = 0; tData.timeMax = delay; }
/// <summary> /// 立即结束timeOut /// </summary> public void finishTimeOut(int index) { TimeExecuteData tData = _timeExDic.get(index); if (tData == null) { return; } clearTimeOut(index); executeTimeExFunc(tData); }
/// <summary> /// 延迟delay毫秒,执行方法 /// </summary> public int setTimeOut(Action func, int delay) { if (delay <= 0) { Ctrl.throwError("传入的时间间隔<=0", delay); return(-1); } TimeExecuteData tData = new TimeExecuteData(); tData.func = func; tData.timeMax = delay; tData.isGoOn = false; return(addTimeEx(tData)); }
/// <summary> /// 间隔delay毫秒,执行方法(如掉帧,只回调一次) /// </summary> public int setInterval(Action <int> func, int delay) { if (delay <= 0) { Ctrl.throwError("传入的时间间隔<=0", delay); return(-1); } TimeExecuteData tData = new TimeExecuteData(); tData.intFunc = func; tData.timeMax = delay; tData.isGoOn = true; tData.isCut = true; return(addTimeEx(tData)); }
private void executeTimeExFunc(TimeExecuteData tData) { try { if (tData.isCut) { tData.intFunc(tData.intArg); } else { tData.func(); } } catch (Exception e) { Ctrl.errorLog(e); } }
/** 移除timeEx */ private void removeTimeEx(int index) { if (index <= 0) { Ctrl.throwError("timeIndex不能<=0"); return; } TimeExecuteData tData = _timeExDic.get(index); if (tData == null) { return; } _timeExDic.remove(index); }