public void AddFrame(Frame frame)
		{
			if(frame == null)
			{
				throw new ArgumentException();
			}
			
			if(_frameList.IndexOf(frame) < 0)
			{

				_frameList.Add(frame);
			
			}
			else
			{
				throw new ArgumentException();
			}
		}
		private static Frame parseMainFrame(Dictionary<String, Object> frameObject, uint frameRate)
		{
			Frame frame = new Frame();
			parseFrame(frameObject, frame, frameRate);
			return frame;
		}
		private static void parseFrame(Dictionary<String, Object> frameObject, Frame frame, uint frameRate)
		{
			frame.Duration = (float)frameObject[ConstValues.A_DURATION] / frameRate;
			if(frameObject.ContainsKey(ConstValues.A_ACTION))
			    frame.Action = frameObject[ConstValues.A_ACTION] as String;
			if(frameObject.ContainsKey(ConstValues.A_EVENT))
			    frame.Evt = frameObject[ConstValues.A_EVENT] as String;
			if(frameObject.ContainsKey(ConstValues.A_SOUND))
			    frame.Sound = frameObject[ConstValues.A_SOUND] as String;
		}
		private void clearVaribles()
		{
			_armature = null;
			_currentFrame = null;
			_clip = null;
			_mixingTransforms = null;

			String[] keys = new string[_timelineStates.Count];
			int i = 0;
			
			foreach(KeyValuePair<string, TimelineState> timelineState in _timelineStates)
			{
				keys[i] = timelineState.Key;
				i++;
				//removeTimelineState(timelineState.Key);
			}

			for(int j=0;j<keys.Length;j++)
			{
				removeTimelineState(keys[j]);
			}
		}
		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;
		}
Beispiel #6
0
		/** @private */
		public void arriveAtFrame(Frame frame, TimelineState timelineState, AnimationState animationState, bool isCross)
		{
			if(frame!=null)
			{
				int mixingType = animationState.GetMixingTransform(Name);
				if(animationState.DisplayControl && (mixingType == 2 || mixingType == -1))
				{
					if(
						DisplayController==null || DisplayController == animationState.Name
						)
					{
						TransformFrame tansformFrame = frame as TransformFrame;
						if(_slot!=null)
						{
							int displayIndex = tansformFrame.DisplayIndex;
							if(displayIndex >= 0)
							{
								if(!float.IsNaN(tansformFrame.ZOrder) && tansformFrame.ZOrder != _slot._tweenZorder)
								{
									_slot._tweenZorder = tansformFrame.ZOrder;
									this._armature._slotsZOrderChanged = true;
								}
							}
							_slot.changeDisplay(displayIndex);
							_slot.updateVisible(tansformFrame.Visible);
						}
					}
				}
				
				if(frame.Evt!=null && this._armature.HasEventListener(FrameEvent.BONE_FRAME_EVENT))
				{
					FrameEvent frameEvent = new FrameEvent(FrameEvent.BONE_FRAME_EVENT);
					frameEvent.Bone = this;
					frameEvent.AnimationState = animationState;
					frameEvent.FrameLabel = frame.Evt;
					this._armature._eventList.Add(frameEvent);
				}
				
				if(frame.Sound!=null && _soundManager.HasEventListener(SoundEvent.SOUND))
				{
					SoundEvent soundEvent = new SoundEvent(SoundEvent.SOUND);
					soundEvent.Armature = this._armature;
					soundEvent.AnimationState = animationState;
					soundEvent.Sound = frame.Sound;
					_soundManager.DispatchEvent(soundEvent);
				}
				
				if(frame.Action!=null)
				{
					foreach(DBObject child in _children)
					{
						if(child is Slot)
						{
							Armature childArmature = (child as Slot).ChildArmature;
							if(childArmature!=null)
							{
								childArmature.Animation.GotoAndPlay(frame.Action);
							}
						}
					}
				}
			}
			else
			{
				if(_slot!=null)
				{
					_slot.changeDisplay(-1);
				}
			}
		}