public bool AdvanceTime(float passedTime) { AnimationEvent evt; bool isComplete = false; if(_fadeIn) { _fadeIn = false; _armature.Animation.setActive(this, true); if(_armature.HasEventListener(AnimationEvent.FADE_IN)) { evt = new AnimationEvent(AnimationEvent.FADE_IN); evt.AnimationState = this; _armature._eventList.Add(evt); } } if(_fadeOut) { _fadeOut = false; _armature.Animation.setActive(this, true); if(_armature.HasEventListener(AnimationEvent.FADE_OUT)) { evt = new AnimationEvent(AnimationEvent.FADE_OUT); evt.AnimationState = this; _armature._eventList.Add(evt); } } //Logger.Log("count " + passedTime + " " + _timeScale ); _currentTime += passedTime * _timeScale; if(_isPlaying && !_isComplete && _pauseBeforeFadeInCompleteState!=0) { float progress; int currentLoopCount; if(_pauseBeforeFadeInCompleteState == -1) { _pauseBeforeFadeInCompleteState = 0; progress = 0; currentLoopCount = (int)progress; } else { progress = _currentTime / _totalTime; //update loopCount currentLoopCount = (int)progress; if(currentLoopCount != _loopCount) { if(_loopCount == -1) { _armature.Animation.setActive(this, true); if(_armature.HasEventListener(AnimationEvent.START)) { evt = new AnimationEvent(AnimationEvent.START); evt.AnimationState = this; _armature._eventList.Add(evt); } } _loopCount = currentLoopCount; if(_loopCount!=0) { if(_loop !=0 && _loopCount * _loopCount >= _loop * _loop - 1) { isComplete = true; progress = 1; currentLoopCount = 0; if(_armature.HasEventListener(AnimationEvent.COMPLETE)) { evt = new AnimationEvent(AnimationEvent.COMPLETE); evt.AnimationState = this; _armature._eventList.Add(evt); } } else { if(_armature.HasEventListener(AnimationEvent.LOOP_COMPLETE)) { evt = new AnimationEvent(AnimationEvent.LOOP_COMPLETE); evt.AnimationState = this; _armature._eventList.Add(evt); } } } } } foreach(KeyValuePair<string, TimelineState> timeline in _timelineStates) { //Logger.Log(timeline.Key); (timeline.Value as TimelineState).Update(progress); //break; } if(_clip.FrameList.Count > 0) { float playedTime = _totalTime * (progress - currentLoopCount); bool isArrivedFrame = false; int frameIndex; while(_currentFrame ==null || playedTime > _currentFrame.Position + _currentFrame.Duration || playedTime < _currentFrame.Position) { if(isArrivedFrame) { _armature.arriveAtFrame(_currentFrame, null, this, true); } isArrivedFrame = true; if(_currentFrame!=null) { frameIndex = _clip.FrameList.IndexOf(_currentFrame); frameIndex ++; if(frameIndex >= _clip.FrameList.Count) { frameIndex = 0; } _currentFrame = _clip.FrameList[frameIndex]; } else { _currentFrame = _clip.FrameList[0]; } } if(isArrivedFrame) { _armature.arriveAtFrame(_currentFrame, null, this, false); } } } //update weight and fadeState if(_fadeState > 0) { if(_fadeInTime == 0) { _fadeWeight = 1; _fadeState = 0; _pauseBeforeFadeInCompleteState = 1; _armature.Animation.setActive(this, false); if(_armature.HasEventListener(AnimationEvent.FADE_IN_COMPLETE)) { evt = new AnimationEvent(AnimationEvent.FADE_IN_COMPLETE); evt.AnimationState = this; _armature._eventList.Add(evt); } } else { _fadeWeight = _currentTime / _fadeInTime; if(_fadeWeight >= 1) { _fadeWeight = 1; _fadeState = 0; if(_pauseBeforeFadeInCompleteState == 0) { _currentTime -= _fadeInTime; } _pauseBeforeFadeInCompleteState = 1; _armature.Animation.setActive(this, false); if(_armature.HasEventListener(AnimationEvent.FADE_IN_COMPLETE)) { evt = new AnimationEvent(AnimationEvent.FADE_IN_COMPLETE); evt.AnimationState = this; _armature._eventList.Add(evt); } } } } else if(_fadeState < 0) { if(_fadeOutTime == 0) { _fadeWeight = 0; _fadeState = 0; _armature.Animation.setActive(this, false); if(_armature.HasEventListener(AnimationEvent.FADE_OUT_COMPLETE)) { evt = new AnimationEvent(AnimationEvent.FADE_OUT_COMPLETE); evt.AnimationState = this; _armature._eventList.Add(evt); } return true; } else { _fadeWeight = (1 - (_currentTime - _fadeOutBeginTime) / _fadeOutTime) * _fadeOutWeight; if(_fadeWeight <= 0) { _fadeWeight = 0; _fadeState = 0; _armature.Animation.setActive(this, false); if(_armature.HasEventListener(AnimationEvent.FADE_OUT_COMPLETE)) { evt = new AnimationEvent(AnimationEvent.FADE_OUT_COMPLETE); evt.AnimationState = this; _armature._eventList.Add(evt); } return true; } } } if(isComplete) { _isComplete = true; if(_loop < 0) { float r = 0f; if(!float.IsNaN(_fadeInTime)&&_fadeInTime!=0) r = _fadeInTime; if(!float.IsNaN(_fadeOutWeight)&&_fadeOutWeight!=0) r = _fadeOutWeight; FadeOut(r / _timeScale, true); } else { _armature.Animation.setActive(this, false); } } return false; }
/** * @private * @return */ override public Event clone() { AnimationEvent evt = new AnimationEvent(this.EventType); evt.AnimationState = AnimationState; return evt; }