/// <summary> /// Plays the target clip /// </summary> /// <param name="targetFrame">Target clip to be played</param> /// <param name="speedModifier">The speed modifier</param> private void PlayClip(AnimatableClip targetFrame, float speedModifier = 1.0f) { this._currentClip = targetFrame; this._currentIndex = 0; this._timeTillNextFrame = targetFrame.Frames.First().Delay *speedModifier; this._renderer.sprite = this._sprites[targetFrame.StartingIndex]; this._speedModifier = speedModifier; }
/// <summary> /// Called once per frame /// </summary> protected virtual void Update() { // Nothing to play if (this._currentClip == null) { return; } this._timeTillNextFrame -= Time.deltaTime; // Not time to switch yet if (this._timeTillNextFrame > 0) { return; } this._currentIndex++; // Reached the end of clip if (this._currentIndex >= this._currentClip.ClipCount) { var nextClip = this._currentClip.TransitTo; if (!String.IsNullOrEmpty(nextClip)) { this.PlayClip(nextClip, this._speedModifier, true); } else { this._currentClip = null; } return; } var targetFrame = this._currentClip.Frames[this._currentIndex]; var targetFrameIndex = targetFrame.Index; if (targetFrameIndex >= this._sprites.Count) { Debug.LogError("Sprite index out of range: " + this._currentIndex); return; } this._renderer.sprite = this._sprites[targetFrameIndex]; if (this.DecalRenderer != null) { this.DecalRenderer.sprite = this._decals[targetFrameIndex]; } this._timeTillNextFrame = targetFrame.Delay * this._speedModifier; }