Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (gameData.state == GameState.Choosing)
        {
            if (IsMouseDown() && !gameData.isCardDragging)
            {
                gameData.isCardDragging = true;
                gameData.dragLastPos    = GetMousePosition();
            }

            if (IsMouseUp())
            {
                gameData.isCardDragging = false;
                var delta = sceneData.cardCurrent.position - sceneData.cardStartPos.position;

                if (Mathf.Abs(delta.x) > sceneData.GetHalfZoneX())
                {
                    sceneData.cardCurrent.SetFlipOut();

                    foreach (var res in sceneData.resources)
                    {
                        var change = (delta.x > 0f) ? res.changeOnRight : res.changeOnLeft;
                        res.SetChange(change);
                    }

                    CreateNewCard();
                }
                else
                {
                    sceneData.cardCurrent.SetReturn();

                    foreach (var res in sceneData.resources)
                    {
                        res.HideHint();
                    }
                }
            }

            if (gameData.isCardDragging && sceneData.cardCurrent.state == CardData.CardState.CanDrag)
            {
                var dragNowPos = GetMousePosition();
                var dragDelta  = dragNowPos - gameData.dragLastPos;

                var delta   = sceneData.cardCurrent.position - sceneData.cardStartPos.position;
                var delta01 = Mathf.Sign(delta.x) * Mathf.Clamp01(Mathf.Abs(delta.x) / sceneData.GetHalfZoneX());

                gameData.dragLastPos = dragNowPos;
                sceneData.cardCurrent.SetPosByDrag(dragDelta);

                foreach (var res in sceneData.resources)
                {
                    var change = (delta.x > 0f) ? res.changeOnRight : res.changeOnLeft;
                    res.ShowHint(change, delta01);
                }
            }
        }
    }