Exemple #1
0
    void Update()
    {
        if (currMenu == CurrMenu.PreGameMenu && allowPlayerSwipe)
        {
            if (Input.GetMouseButtonDown(0))
            {
                startPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                StatsUI.Hide();
            }

            if (startPosition != Vector3.zero)
            {
                float deltaX = Camera.main.ScreenToWorldPoint(Input.mousePosition).x - startPosition.x;

                if (deltaX != 0)
                {
                    float swipePersent = Mathf.Abs(deltaX) / swipeDist;
                    for (byte i = 0; i < PlayerSpritesMainMenu.Length; ++i)
                    {
                        if (deltaX > 0)
                        {
                            PlayerSpritesMainMenu[i].transform.localPosition = new Vector3(
                                (i - currPlayerSprite) * 1450 + 1450 * swipePersent,
                                450 + (i - currPlayerSprite) * 950 + 950 * swipePersent,
                                PlayerSpritesMainMenu[i].transform.localPosition.z
                                );
                        }
                        else
                        {
                            PlayerSpritesMainMenu[i].transform.localPosition = new Vector3(
                                (i - currPlayerSprite) * 1450 + 1450 * swipePersent * -1,
                                450 + (i - currPlayerSprite) * 950 + 950 * swipePersent * -1,
                                PlayerSpritesMainMenu[i].transform.localPosition.z
                                );
                        }
                    }
                }

                if (Input.GetMouseButtonUp(0))
                {
                    endPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    float swipePersent = Mathf.Abs(endPosition.x - startPosition.x) / swipeDist;
                    int   swipeTimes   = Mathf.RoundToInt(swipePersent);

                    if (startPosition != endPosition && swipeTimes != 0)
                    {
                        if (startPosition.x < endPosition.x)
                        {
                            while (currPlayerSprite != 0 && swipeTimes-- != 0)
                            {
                                --currPlayerSprite;
                            }
                        }
                        else
                        {
                            while (currPlayerSprite != PlayerSpritesMainMenu.Length - 1 && swipeTimes-- != 0)
                            {
                                ++currPlayerSprite;
                            }
                        }
                    }

                    ChangePlayerSprite();
                    startPosition = endPosition = Vector3.zero;
                }
            }
        }

        void ChangePlayerSprite()
        {
            PlayerPrefs.SetInt("MenuController.currPlayerSprite", currPlayerSprite);

            for (byte i = 0; i < PlayerSpritesMainMenu.Length; ++i)
            {
                LeanTween.move(PlayerSpritesMainMenu[i], new Vector2((i - currPlayerSprite) * 1450, 450 + (i - currPlayerSprite) * 950), Consts.menuAnimationsTime / 6)
                .setEase(LeanTweenType.linear);
            }

            LeanTween.delayedCall(Consts.menuAnimationsTime / 6, () => {
                if (currMenu == CurrMenu.PreGameMenu)
                {
                    StatsUI.Show();
                }
            });

            //TODO: call only on start game
            ChangePlayerSkin();
        }
    }