Ejemplo n.º 1
0
        public void Update()
        {
            if (!HighLogic.LoadedSceneIsFlight)
            {
                return;
            }

            try
            {
                switch (CurrentState)
                {
                // System is inactive, and playing the inactive animation if present
                case State.Inactive:
                    if (ConvertersEnabled())
                    {
                        if (waitForComplete)
                        {
                            DeployWait();
                        }
                        else
                        {
                            DeployStart();
                        }
                    }

                    break;

                // System is inactive, but waiting for the animation to end before deploying
                case State.InactiveWaiting:
                    if (!waitForComplete || !_inactiveAnimationPresent)
                    {
                        this.LogError(
                            "Invalid state! waitForComplete not enabled or inactive animation not present.");
                        CurrentState = State.Inactive;
                    }
                    else if (!ConvertersEnabled())
                    {
                        RetractEnd();
                    }
                    else if (!InactiveAnimation.IsPlaying(inactiveAnimationName))
                    {
                        DeployStart();
                    }

                    break;

                // System is deploying
                case State.Deploying:
                    if (!_deployAnimationPresent)
                    {
                        this.LogError("Invalid state! Deploying without an animation present.");
                        CurrentState = State.Active;
                    }
                    else if (!ConvertersEnabled())
                    {
                        RetractStart();
                    }
                    else if (!DeployAnimation.IsPlaying(deployAnimationName))
                    {
                        DeployEnd();
                    }

                    break;

                // System is active, and playing the active animation if present
                case State.Active:
                    if (!ConvertersEnabled())
                    {
                        if (waitForComplete)
                        {
                            RetractWait();
                        }
                        else
                        {
                            RetractStart();
                        }
                    }

                    break;

                // System is active, but waiting for the animation to finish before retracting
                case State.ActiveWaiting:
                    if (!waitForComplete || !_activeAnimationPresent)
                    {
                        this.LogError(
                            "Invalid state! waitForComplete not enabled or active animation not present.");
                        CurrentState = State.Active;
                    }
                    else if (ConvertersEnabled())
                    {
                        DeployEnd();
                    }
                    else if (!ActiveAnimation.IsPlaying(activeAnimationName))
                    {
                        RetractStart();
                    }

                    break;

                // System is retracting
                case State.Retracting:
                    if (!_retractAnimationPresent && !_deployAnimationPresent)
                    {
                        this.LogError("Invalid state! Retracting without an animation present.");
                        CurrentState = State.Inactive;
                    }
                    else if (ConvertersEnabled())
                    {
                        DeployStart();
                    }
                    else if (_retractAnimationPresent)
                    {
                        if (!RetractAnimation.IsPlaying(retractAnimationName))
                        {
                            RetractEnd();
                        }
                    }
                    else if (_deployAnimationPresent)
                    {
                        if (!DeployAnimation.IsPlaying(deployAnimationName))
                        {
                            RetractEnd();
                        }
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
                this.LogException("Failed to update animation module", e);
            }
        }