コード例 #1
0
        private void Update()
        {
            // Read input

            bool left  = false;
            bool right = false;
            bool up    = false;
            bool down  = false;

            if (acceptInput)
            {
                BeetleControls controls = Game.BEETLE_CONTROLS[index];

                if (controls.useGamepad)
                {
                    float h = Input.GetAxisRaw(controls.hor);
                    float v = Input.GetAxisRaw(controls.ver);

                    left  = (h < -0.5f && h < gamepadHorPrev);
                    right = (h > +0.5f && h > gamepadHorPrev);
                    up    = (v < -0.5f && v < gamepadVerPrev);
                    down  = (v > +0.5f && v > gamepadVerPrev);

                    gamepadHorPrev = h;
                    gamepadVerPrev = v;
                }

                else
                {
                    left  = Input.GetKeyDown(controls.left);
                    right = Input.GetKeyDown(controls.right);
                    up    = Input.GetKeyDown(controls.up);
                    down  = Input.GetKeyDown(controls.down);
                }
            }

            // ====================================================================================

            // Allow customization

            switch (state)
            {
            case State.ModelSelect:

                messageText.text = "CHOOSE A MODEL";

                if (down)
                {
                    state = State.PaletteSelect;
                }
                else
                {
                    int cur = Game.BEETLE_MODEL_CHOICE[index];
                    int add = (right ? 1 : 0) - (left ? 1 : 0);
                    int len = data.models.Length;

                    Game.BEETLE_MODEL_CHOICE[index] = (cur + add + len) % len;

                    if (add != 0)
                    {
                        visuals.UpdateAppearance();
                        visuals.Jiggle(Mathf.Abs(add) * -0.05f);

                        MusicManager.Play(Sound.Tick);
                        messageX.velocity += add * 10f;
                    }
                }

                break;

            case State.PaletteSelect:

                messageText.text = "CHOOSE A PALETTE";

                if (down)
                {
                    state = State.Ready;
                }
                else if (up)
                {
                    state = State.ModelSelect;
                }
                else
                {
                    int cur = Game.BEETLE_PALETTE_CHOICE[index];
                    int add = (right ? 1 : 0) - (left ? 1 : 0);
                    int len = data.palettes.Length;

                    Game.BEETLE_PALETTE_CHOICE[index] = (cur + add + len) % len;

                    if (add != 0)
                    {
                        visuals.UpdateAppearance();
                        visuals.Jiggle(Mathf.Abs(add) * -0.05f);

                        MusicManager.Play(Sound.Tick);
                        messageX.velocity += add * 10f;
                    }
                }

                break;

            case State.Ready:

                messageText.text = "READY!";

                if (up)
                {
                    state = State.PaletteSelect;
                }
                break;
            }

            if (up != down)
            {
                MusicManager.Play(Sound.Select);
                messageY.velocity += (up ? 5f : 0f) - (down ? 5f : 0f);
            }

            // ====================================================================================

            visuals.transform.rotation = Quaternion.Euler(0, index * 120f + Time.time * 20f, 0);
            messageText.rectTransform.anchoredPosition = new Vector2(messageX, messageY - 25);
        }