private void setLegState(LegState newState)
        {
            LegState prevState = legState;
            legState = newState;
            persistentState = legState.ToString();

            switch(newState)
            {

            case LegState.BROKEN:
            {
                enableWheelColliders(false);
                enableFootColliders(false);
                animationController.setToState(SSTUAnimState.STOPPED_START);
                decompressTime = 0;
                break;
            }

            case LegState.DEPLOYED:
            {
                animationController.setToState(SSTUAnimState.STOPPED_END);
                decompressTime = 0;
                if(HighLogic.LoadedSceneIsFlight)
                {
                    enableWheelColliders(true);
                    enableFootColliders(false);
                }
                break;
            }

            case LegState.RETRACTED:
            {
                enableWheelColliders(false);
                enableFootColliders(false);
                decompressTime = 0;
                animationController.setToState(SSTUAnimState.STOPPED_START);
                break;
            }

            case LegState.DEPLOYING:
            {
                if(decompressTime>0)//decompress/retracting; just stop decompressing, disable foot colliders, and set state to deployed;
                {
                    decompressTime = 0;
                    legState = LegState.DEPLOYED;
                    enableFootColliders(false);
                    enableWheelColliders(true);
                    break;
                }
                else
                {
                    enableWheelColliders(false);
                    decompressTime = 0;
                    resetSuspensionPosition();//just in case something got fubard
                    if(HighLogic.LoadedSceneIsFlight)
                    {
                        enableFootColliders(true);
                        animationController.setToState(SSTUAnimState.PLAYING_FORWARD);
                    }
                    else//we are in editor
                    {
                        legState = LegState.DEPLOYED;
                        animationController.setToState(SSTUAnimState.STOPPED_END);
                    }
                    break;
                }
            }

            case LegState.RETRACTING:
            {
                enableFootColliders(true);
                if(prevState==LegState.DEPLOYED)//fix for 'instant retract' bug on newly loaded vessel
                {
                    if(HighLogic.LoadedSceneIsFlight)
                    {
                        decompressTime = 1.0f;
                        //from here the decompress logic will trigger retract animation when it is needed...
                    }
                    else//else we are in editor, do not bother with retract decompress, go straight to playing animation;
                    {
                        //TODO instant-retract when in editor
                        resetSuspensionPosition();
                        animationController.setToState(SSTUAnimState.STOPPED_START);
                        legState=LegState.RETRACTED;
                    }
                }
                else
                {
                    if(HighLogic.LoadedSceneIsFlight)
                    {
                        resetSuspensionPosition();
                        enableWheelColliders(false);
                        animationController.setToState(SSTUAnimState.PLAYING_BACKWARD);
                    }
                    else
                    {
                        resetSuspensionPosition();
                        animationController.setToState(SSTUAnimState.STOPPED_START);
                        legState=LegState.RETRACTED;
                    }
                }
                break;
            }

            }//end switch

            updateGuiControlsFromState();
        }
示例#2
0
        private void setLegState(LegState newState)
        {
            LegState prevState = legState;

            legState        = newState;
            persistentState = legState.ToString();

            switch (newState)
            {
            case LegState.BROKEN:
            {
                enableWheelColliders(false);
                enableFootColliders(false);
                animationController.setToState(AnimState.STOPPED_START);
                decompressTime = 0;
                break;
            }

            case LegState.DEPLOYED:
            {
                animationController.setToState(AnimState.STOPPED_END);
                decompressTime = 0;
                if (HighLogic.LoadedSceneIsFlight)
                {
                    enableWheelColliders(true);
                    enableFootColliders(false);
                }
                break;
            }

            case LegState.RETRACTED:
            {
                enableWheelColliders(false);
                enableFootColliders(false);
                decompressTime = 0;
                animationController.setToState(AnimState.STOPPED_START);
                break;
            }

            case LegState.DEPLOYING:
            {
                if (decompressTime > 0)        //decompress/retracting; just stop decompressing, disable foot colliders, and set state to deployed;
                {
                    decompressTime = 0;
                    legState       = LegState.DEPLOYED;
                    enableFootColliders(false);
                    enableWheelColliders(true);
                    break;
                }
                else
                {
                    enableWheelColliders(false);
                    decompressTime = 0;
                    resetSuspensionPosition();        //just in case something got fubard
                    if (HighLogic.LoadedSceneIsFlight)
                    {
                        enableFootColliders(true);
                        animationController.setToState(AnimState.PLAYING_FORWARD);
                    }
                    else        //we are in editor
                    {
                        legState = LegState.DEPLOYED;
                        animationController.setToState(AnimState.STOPPED_END);
                    }
                    break;
                }
            }

            case LegState.RETRACTING:
            {
                enableFootColliders(true);
                if (prevState == LegState.DEPLOYED)        //fix for 'instant retract' bug on newly loaded vessel
                {
                    if (HighLogic.LoadedSceneIsFlight)
                    {
                        decompressTime = 1.0f;
                        //from here the decompress logic will trigger retract animation when it is needed...
                    }
                    else
                    {
                        //else we are in editor, go straight to retracted state
                        resetSuspensionPosition();
                        animationController.setToState(AnimState.STOPPED_START);
                        legState = LegState.RETRACTED;
                    }
                }
                else
                {
                    if (HighLogic.LoadedSceneIsFlight)
                    {
                        resetSuspensionPosition();
                        enableWheelColliders(false);
                        animationController.setToState(AnimState.PLAYING_BACKWARD);
                    }
                    else
                    {
                        resetSuspensionPosition();
                        animationController.setToState(AnimState.STOPPED_START);
                        legState = LegState.RETRACTED;
                    }
                }
                break;
            }
            }//end switch

            updateGuiControlsFromState();
        }