public void CopyState(Spritesheet <T> other) { AnimationFrame = other.AnimationFrame; Playing = other.Playing; Finished = other.Finished; CurrentAnimID = other.CurrentAnimID; Rate = other.Rate; currentFrame = other.currentFrame; currentAnim = other.currentAnim; timer = other.timer; }
/* * Playing animations */ public void Play(T id, bool restart = false) { if (restart || (!Playing && !Finished) || !CurrentAnimID.Equals(id)) { CurrentAnimID = id; currentAnim = Animations[id]; AnimationFrame = 0; currentFrame = currentAnim[AnimationFrame]; timer = 0; Finished = false; Playing = true; } }
/* * Animation definition */ public void Add(T id, float delay, bool loop, params int[] frames) { #if DEBUG foreach (var i in frames) { if (i >= FrameRects.Length) { throw new Exception("Specified frames is out of max range for this Sprite."); } } #endif var anim = new SpritesheetAnimation(delay, loop, frames); Animations.Add(id, anim); }
public override void ProcessFrame(Playable playable, FrameData info, object playerData) { SpritesheetAnimation spritesheetAnimation = playerData as SpritesheetAnimation; if (!spritesheetAnimation) { return; } int numberOfClips = playable.GetInputCount(); bool playedClip = false; for (int i = 0; i < numberOfClips; i++) { float currentClipWeight = playable.GetInputWeight(i); ScriptPlayable <SpritesheetAnimationBehaviour> scriptPlayable = (ScriptPlayable <SpritesheetAnimationBehaviour>)playable.GetInput(i); SpritesheetAnimationBehaviour spritesheetBehaviour = scriptPlayable.GetBehaviour(); if (currentClipWeight > 0) { if (!spritesheetBehaviour.isPlaying && spritesheetBehaviour.spritesheetTexture) { spritesheetBehaviour.isPlaying = true; spritesheetAnimation.SetSpritesheetTexture(spritesheetBehaviour.spritesheetTexture, spritesheetBehaviour.frameCount, spritesheetBehaviour.framesPerSecond); spritesheetAnimation.StartAnimating(); isStopped = false; } playedClip = true; } else { spritesheetBehaviour.isPlaying = false; } } if (!playedClip && !isStopped) { spritesheetAnimation.StopAnimating(); isStopped = true; } }