private void ElapsedInt(ulong millSinceBeginning = 0) { while (true) { lock (_tempPaths) { if (_tempPaths != null && ActivePath == null && _tempPaths.Count > 0) { while (ActivePath == null) { if (_tempReverseRepeat) { ActivePath = _tempPaths.LastOrDefault(); _tempPaths.RemoveAt(_tempPaths.Count - 1); } else { ActivePath = _tempPaths.FirstOrDefault(); _tempPaths.RemoveAt(0); } _timer.ResetClock(); millSinceBeginning = 0; } } var ended = ActivePath == null; if (ActivePath != null) { if (!_tempReverseRepeat && millSinceBeginning < ActivePath.Delay) { CurrentStatus = AnimatorStatus.OnHold; return; } if (millSinceBeginning - (!_tempReverseRepeat ? ActivePath.Delay : 0) <= ActivePath.Duration) { if (CurrentStatus != AnimatorStatus.Playing) { CurrentStatus = AnimatorStatus.Playing; } var value = ActivePath.Function(_tempReverseRepeat ? ActivePath.Duration - millSinceBeginning : millSinceBeginning - ActivePath.Delay, ActivePath.Start, ActivePath.Change, ActivePath.Duration); FrameCallbackInt.Invoke((int)value); return; } if (CurrentStatus == AnimatorStatus.Playing) { if (_tempPaths.Count == 0) { // For the last path, we make sure that control is in end point FrameCallbackInt.Invoke(_tempReverseRepeat ? (int)ActivePath.Start : (int)ActivePath.End); ended = true; } else { if ((_tempReverseRepeat && ActivePath.Delay > 0) || !_tempReverseRepeat && _tempPaths.FirstOrDefault()?.Delay > 0) { // Or if the next path or this one in revese order has a delay FrameCallbackInt.Invoke(_tempReverseRepeat ? (int)ActivePath.Start : (int)ActivePath.End); } } } if (_tempReverseRepeat && (millSinceBeginning - ActivePath.Duration) < ActivePath.Delay) { CurrentStatus = AnimatorStatus.OnHold; return; } ActivePath = null; } if (!ended) { return; } } if (Repeat) { lock (_tempPaths) { _tempPaths.AddRange(_paths); _tempReverseRepeat = ReverseRepeat && !_tempReverseRepeat; } millSinceBeginning = 0; continue; } Stop(); EndCallback?.Invoke(); break; } }
private void Elapsed(ulong millSinceBeginning) { lock (_tempPaths) { if (_tempPaths != null && ActivePath == null && _tempPaths.Count > 0) { while (ActivePath == null) { if (_tempReverseRepeat) { ActivePath = _tempPaths.LastOrDefault(); _tempPaths.RemoveAt(_tempPaths.Count - 1); } else { ActivePath = _tempPaths.FirstOrDefault(); _tempPaths.RemoveAt(0); } _timer.ResetClock(); millSinceBeginning = 0; } } if (ActivePath != null) { if (!_tempReverseRepeat && millSinceBeginning < ActivePath.Delay) { CurrentStatus = AnimatorStatus.OnHold; return; } if (millSinceBeginning - (!_tempReverseRepeat ? ActivePath.Delay : 0) <= ActivePath.Duration) { if (CurrentStatus != AnimatorStatus.Playing) { FrameCallback.Invoke(_tempReverseRepeat ? ActivePath.End : ActivePath.Start); CurrentStatus = AnimatorStatus.Playing; } var value = ActivePath.Function( _tempReverseRepeat ? ActivePath.Duration - millSinceBeginning : millSinceBeginning - ActivePath.Delay, ActivePath.Start, ActivePath.Change, ActivePath.Duration); FrameCallback.Invoke(value); return; } if (CurrentStatus == AnimatorStatus.Playing) { FrameCallback.Invoke(_tempReverseRepeat ? ActivePath.Start : ActivePath.End); } if (_tempReverseRepeat && (millSinceBeginning - ActivePath.Duration) < ActivePath.Delay) { CurrentStatus = AnimatorStatus.OnHold; return; } ActivePath = null; } else if (Repeat) { lock (_tempPaths) { _tempPaths.AddRange(_paths); _tempReverseRepeat = ReverseRepeat && !_tempReverseRepeat; } } else { Stop(); EndCallback?.Invoke(); } } }