private ThirdState() { if (_instance != null) { return; } _instance = this; }
public BusyContainerStackViewModel(ILogger logger) { Logger = logger ?? throw new ArgumentNullException(nameof(logger)); Content = new StackBusyState(); FirstStateCommands = new List <IUICommand> { new RelayUICommand(() => FirstState = Content.Push("First state title", "First state description"), () => FirstState == null) { Title = "Initialize" }, new RelayUICommand(() => { FirstState.Dispose(); FirstState = null; }, () => FirstState != null) { Title = "Reset" }, new RelayUICommand(async() => await PayloadBackgroundOperation(FirstState), () => FirstState != null) { Title = "Payload" } }; SecondStateCommands = new List <IUICommand> { new RelayUICommand(() => SecondState = Content.Push("Second state title", "Second state description"), () => SecondState == null) { Title = "Initialize" }, new RelayUICommand(() => { SecondState.Dispose(); SecondState = null; }, () => SecondState != null) { Title = "Reset" } }; ThirdStateCommands = new List <IUICommand> { new RelayUICommand(() => ThirdState = Content.Push("Third state title", "Third state description"), () => ThirdState == null) { Title = "Initialize" }, new RelayUICommand(() => { ThirdState.Dispose(); ThirdState = null; }, () => ThirdState != null) { Title = "Reset" } }; }
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()); }