public override void Update(GameTime gameTime) { if (ifInterpolate) { CalculateInterpolationAmount(gameTime, this.currentInterpolationTimeMS, this.interDirection, ref this.currentInterpolation); if (currentInterpolation >= 1.0f) { this.CurrentState = NewState; this.NewState = null; this.currentInterpolation = 0.0f; this.currentInterpolationTimeMS = 0; this.ifInterpolate = false; } else if (currentInterpolation <= 0.0f) { this.interDirection = 1.0f; this.NewState = null; this.currentInterpolation = 0.0f; this.currentInterpolationTimeMS = 0; this.ifInterpolate = false; } } if (ifHelperInterpolate) { //Debug.Log(this.hCurrentInterpolation.ToString() + " " + gameTime.TotalGameTime.Seconds.ToString()); CalculateInterpolationAmount(gameTime, this.hCurrentInterpolationTimeMS, this.hInterDirection, ref this.hCurrentInterpolation); if (hCurrentInterpolation >= 1.0f && this.hInterDirection == 1.0f) // we've interpolated TO and playing this animation atm { this.ifHelperInterpolate = false; } else if (hCurrentInterpolation <= 0.0f && this.hInterDirection == -1.0f) // we've ended this animation permanently { this.ThirdState.Animation.StopClip(); this.ThirdState = null; this.hCurrentInterpolation = 0.0f; this.hCurrentInterpolationTimeMS = 0; this.hInterDirection = 1.0f; this.ifHelperInterpolate = false; } } if (CurrentState != null) { CurrentState.Update(gameTime); } if (NewState != null) { NewState.Update(gameTime); } if (ThirdState != null) { ThirdState.Update(gameTime); } if (ThirdState != null && !ifHelperInterpolate) { // if animation is about to finish, let's interpolate back to original two states // first let's check time we are in now and compare it with "Back" animation transition time TimeSpan backTime = ThirdState.GetTimeByTransition(CurrentState); if (backTime == TimeSpan.Zero) { Debug.Log("ANIMATOR ERROR: ThirdState cannot make a transition to CurrentState, because the latter is not on its transition list."); return; } TimeSpan currentTime = ThirdState.Animation.CurrentTime; TimeSpan durationTime = ThirdState.Animation.CurrentClip.Duration; if (currentTime >= (durationTime - backTime)) { // now launch interpolation back this.hInterDirection = -1.0f; this.hCurrentInterpolationTimeMS = (int)backTime.TotalMilliseconds; this.ifHelperInterpolate = true; this.hCurrentInterpolation = 0.9999f; } } //Debug.Log((CurrentState != null ? CurrentState.Name : "null") + " " + // (NewState != null ? NewState.Name : "null") + " " + gameTime.TotalGameTime.Seconds.ToString()); }