/// <summary> /// 分帧执行事件(可以指定每帧执行的逻辑次数) /// </summary> /// <param name="_count">总数量</param> /// <param name="_executeCountPerFrame">每帧执行的数量</param> /// <param name="_perAction">每次逻辑执行的回调(不是每帧,每帧会回调frame count次)</param> /// <param name="_complete">完成事件</param> public FramingHandler FramingExecute(int _count, int _executeCountPerFrame, Action <int> _perAction, Action _complete = null) { if (_count <= 0 || _executeCountPerFrame <= 0) { if (null != _complete) { _complete(); } return(null); } var loopFrameCount = _count / _executeCountPerFrame + 1; FramingHandler handler = new FramingHandler(); int executeIndex = 0; handler.PerTimerHandler = timerManager.Make(() => { for (int index = 0; index < _executeCountPerFrame; index++) { executeIndex++; if (executeIndex < _count) { if (null != _perAction) { _perAction(executeIndex); } } } }).LoopFrame(loopFrameCount); handler.CompleteHandler = timerManager.Make(() => { if (null != _complete) { _complete(); } handler.Clear(); }).DelayFrame(loopFrameCount + 1); // 这里结束多延迟一帧,防止和最后一个逻辑帧冲突 return(handler); }
/// <summary> /// 分帧泛型参数执行 /// </summary> /// <param name="_list"></param> /// <param name="_executeCountPerFrame"></param> /// <param name="_perAction"></param> /// <param name="_complete"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public FramingHandler FramingExecuteArgs <T>(List <T> _list, int _executeCountPerFrame, Action <int, T> _perAction, Action _complete = null) { if (null == _list || _list.Count <= 0) { if (null != _complete) { _complete(); } return(null); } var loopFrameCount = _list.Count / _executeCountPerFrame + 1; FramingHandler handler = new FramingHandler(); int executeIndex = 0; handler.PerTimerHandler = timerManager.Make(() => { for (int index = 0; index < _executeCountPerFrame; index++) { if (executeIndex < _list.Count) { var model = _list[executeIndex]; if (null != _perAction) { _perAction(executeIndex, model); } } executeIndex++; } }).LoopFrame(loopFrameCount); handler.CompleteHandler = timerManager.Make(() => { if (null != _complete) { _complete(); } handler.Clear(); }).DelayFrame(loopFrameCount + 1); // 这里结束多延迟一帧,防止和最后一个逻辑帧冲突 return(handler); }