void Update() { if (CurrentAnimation == Animations.GetAnimation(SpriteAnimations.DEAD)) { Renderer.sprite = Dead; return; } // Pending callbacks (cause of animation switches) var pendingCb = PendingCallbacks .Where(c => c.PlayOnFrame == 0) .Select(c => c) .FirstOrDefault(); if (pendingCb != null) { pendingCb.Callback(); PendingCallbacks.Remove(pendingCb); } PendingCallbacks.ForEach(pendingCallback => pendingCallback.PlayOnFrame -= 1); if (CurrentAnimation == null) { Renderer.sprite = GetSheet(Direction)[1]; return; } _deltaTime += Time.deltaTime; while (CurrentAnimation != null && _deltaTime >= CurrentAnimation.AnimationTimeInSeconds) { _deltaTime -= CurrentAnimation.AnimationTimeInSeconds; _animResult = CurrentAnimation.Loop(Direction); // Animation callbacks to be frame-specific var cb = CurrentAnimation.Callbacks? .Where(c => c.PlayOnFrame == CurrentAnimation.CurrentFrame) .Select(c => c) .FirstOrDefault(); if (cb != null) { cb.Callback(); CurrentAnimation.Callbacks?.Remove(cb); } transform.localPosition = new Vector2(_animResult.OffsetX, _animResult.OffsetY); if (CurrentAnimation.IsOver) { Debug.Log("Animation is Over"); CurrentAnimation = null; } } if (_animResult != null) { Renderer.sprite = _animResult.Sprite; } }
public void SetDirection(Direction dir) { if (this.Direction != dir) { this.Direction = dir; if (CurrentAnimation != null) { _animResult = CurrentAnimation.Loop(this.Direction); } } }
public AnimationResult AnimateCircle() { AnimationResult result = AnimationResult.animationRunning; if (currentLife > (endLife + birthDelay)) { result = AnimationResult.animationDone; } else if (currentLife > birthDelay) { radius += radiusStep; opacity += opacityStep; //} else //{ // result = AnimationResult.animationHidden; Not currently used } currentLife++; return(result); }