Example #1
0
        /// <summary>
        /// Loads the animations and hooks into the colliders for this toggle switch.
        /// </summary>
        void Start()
        {
            // no setup needed in editor mode
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                return;
            }

            // retrieve the animation
            Animation[] animations = internalProp.FindModelAnimators(animationName);
            if (animations.Length > 0)
            {
                switchAnimation               = animations[0];
                switchAnimationState          = switchAnimation[animationName];
                switchAnimationState.wrapMode = WrapMode.Once;
            }
            else
            {
                Utils.LogWarning("KVR_ToggleSwitchDouble (" + gameObject.name + ") has no animation \"" + animationName + "\"");
            }

            // retrieve the collider GameObjects
            Transform switchTransform = internalProp.FindModelTransform(transformSwitchColliderUp);

            if (switchTransform != null)
            {
                switchUpGameObject = switchTransform.gameObject;
                switchUpGameObject.AddComponent <KVR_ToggleSwitchCollider>().toggleSwitchComponent = this;
            }
            else
            {
                Utils.LogWarning("KVR_ToggleSwitchDouble (" + gameObject.name + ") has no switch collider \"" + transformSwitchColliderUp + "\"");
            }

            switchTransform = internalProp.FindModelTransform(transformSwitchColliderDown);
            if (switchTransform != null)
            {
                switchDownGameObject = switchTransform.gameObject;
                switchDownGameObject.AddComponent <KVR_ToggleSwitchCollider>().toggleSwitchComponent = this;
            }
            else
            {
                Utils.LogWarning("KVR_ToggleSwitchDouble (" + gameObject.name + ") has no switch collider \"" + transformSwitchColliderDown + "\"");
            }

            // set initial state
            targetAnimationEndTime = 0f;
            switchFSMState         = SwitchFSMState.IsDown;
            SetState(SwitchState.Down);
        }
        private void UpdateSwitchFSM(SwitchStateInput colliderInput)
        {
            switch (switchFSMState)
            {
            case SwitchFSMState.IsUp:
                if (colliderInput == SwitchStateInput.ColliderUpEnter)
                {
                    switchFSMState = SwitchFSMState.IsWaitingForDown;
                }
                break;

            case SwitchFSMState.IsWaitingForDown:
                if (colliderInput == SwitchStateInput.ColliderUpExit)
                {
                    switchFSMState = SwitchFSMState.IsUp;
                }
                else if (colliderInput == SwitchStateInput.ColliderDownEnter)
                {
                    switchFSMState = SwitchFSMState.IsDown;
                    PlayToState(SwitchState.Down);
                }
                break;

            case SwitchFSMState.IsDown:
                if (colliderInput == SwitchStateInput.ColliderDownEnter)
                {
                    switchFSMState = SwitchFSMState.IsWaitingForUp;
                }
                break;

            case SwitchFSMState.IsWaitingForUp:
                if (colliderInput == SwitchStateInput.ColliderDownExit)
                {
                    switchFSMState = SwitchFSMState.IsDown;
                }
                else if (colliderInput == SwitchStateInput.ColliderUpEnter)
                {
                    switchFSMState = SwitchFSMState.IsUp;
                    PlayToState(SwitchState.Up);
                }
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Loads the animations and hooks into the colliders for this toggle switch.
        /// </summary>
        void Start()
        {
            // no setup needed in editor mode
            if (HighLogic.LoadedScene == GameScenes.EDITOR)
            {
                return;
            }

            // retrieve the animation
            Animation[] animations = internalProp.FindModelAnimators(animationName);
            if (animations.Length > 0)
            {
                switchAnimation               = animations[0];
                switchAnimationState          = switchAnimation[animationName];
                switchAnimationState.wrapMode = WrapMode.Once;
            }
            else
            {
                Utils.LogWarning("KVR_ToggleSwitchDouble (" + gameObject.name + ") has no animation \"" + animationName + "\"");
            }

            // retrieve the collider GameObjects
            Transform switchTransform = internalProp.FindModelTransform(transformSwitchColliderUp);

            if (switchTransform != null)
            {
                switchUpGameObject = switchTransform.gameObject;
                switchUpGameObject.AddComponent <KVR_ActionableCollider>().module = this;
            }
            else
            {
                Utils.LogWarning("KVR_ToggleSwitchDouble (" + gameObject.name + ") has no switch collider \"" + transformSwitchColliderUp + "\"");
            }

            switchTransform = internalProp.FindModelTransform(transformSwitchColliderDown);
            if (switchTransform != null)
            {
                switchDownGameObject = switchTransform.gameObject;
                switchDownGameObject.AddComponent <KVR_ActionableCollider>().module = this;
            }
            else
            {
                Utils.LogWarning("KVR_ToggleSwitchDouble (" + gameObject.name + ") has no switch collider \"" + transformSwitchColliderDown + "\"");
            }

            // special effects
            Transform coloredObjectTransform = internalProp.FindModelTransform(coloredObject);

            if (coloredObjectTransform != null)
            {
                coloredGameObject = coloredObjectTransform.gameObject;
                // MeshRenderer r = coloredGameObject.GetComponent<MeshRenderer>();
                // Material rmat = r.sharedMaterial;
                // rmat.SetColor(Shader.PropertyToID("_EmissiveColor"), Color.red);
            }

            // set initial state
            targetAnimationEndTime = 0f;
            switchFSMState         = SwitchFSMState.IsDown;
            GoToState(SwitchState.Down);

            // create labels
            CreateLabels();
        }