Пример #1
0
        private void MoveCardFromStack()
        {
            _collider.enabled = false;

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out RaycastHit hit, 100f))
            {
                CardComponent hittedCard  = hit.transform.GetComponent <CardComponent>();
                CardsStack    hittedStack = hittedCard.CardData.Stack;

                if (hittedCard != null && hittedStack != CardData.Stack)
                {
                    InsertCartToAnotherStack(hittedCard, hittedStack);
                }
                else if (hittedCard != null && hittedStack == CardData.Stack)
                {
                    InsertCartToCurrentStack(hittedCard, hittedStack);
                }
            }

            _collider.enabled = true;

            CardData.State = State.InStack;

            CardData.Stack.Reorder();
        }
Пример #2
0
        private void InsertCartToCurrentStack(CardComponent hittedCard, CardsStack hittedStack)
        {
            CardData.Stack.Remove(this);

            int insertIndex = hittedStack.IndexOf(hittedCard);

            hittedStack.InsertAt(this, ++insertIndex);
        }
Пример #3
0
        private void InsertCartToAnotherStack(CardComponent hittedCard, CardsStack hittedStack)
        {
            CardData.Stack.Remove(this);

            int insertIndex = hittedStack.IndexOf(hittedCard);

            hittedStack.InsertAt(this, ++insertIndex);

            transform.SetParent(hittedStack.transform);
            CardData.Stack = hittedCard.CardData.Stack;
        }