Пример #1
0
        public void Sync(CardStack stack)
        {
            _cardStack     = stack;
            nameLabel.text = _cardStack.Name;

            contentCardZone.transform.DestroyAllChildren();
            List <UnityCard> cards = _cardStack.Cards.Reverse().ToList();
            int index = cards.Count - 1;

            foreach (UnityCard card in cards)
            {
                var cardModel = Instantiate(cardModelPrefab, contentCardZone.transform).GetOrAddComponent <CardModel>();
                cardModel.Value = card;
                cardModel.Index = index;
                index--;
            }

            countLabel.text = _cardStack.Cards.Count.ToString();
        }
Пример #2
0
        public void UpdateCardStackPosition(Vector2 targetPosition)
        {
            CardStack cardStack = ParentCardStack;

            if (cardStack == null || (IsOnline && !hasAuthority))
            {
                return;
            }

            if (!cardStack.DoesImmediatelyRelease && (cardStack.type == CardStackType.Vertical || cardStack.type == CardStackType.Horizontal))
            {
                cardStack.UpdateScrollRect(CurrentDragPhase, CurrentPointerEventData);
            }
            else if (!IsStatic)
            {
                cardStack.UpdateLayout(transform as RectTransform, targetPosition);
            }

            if (!IsStatic)
            {
                if (cardStack.type == CardStackType.Area)
                {
                    transform.SetAsLastSibling();
                }

                Vector3[] stackCorners = new Vector3[4];
                ((RectTransform)cardStack.transform).GetWorldCorners(stackCorners);
                bool isOutYBounds = targetPosition.y <stackCorners[0].y || targetPosition.y> stackCorners[1].y;
                bool isOutXBounds = targetPosition.x <stackCorners[0].x || targetPosition.y> stackCorners[2].x;
                if ((cardStack.DoesImmediatelyRelease && !IsProcessingSecondaryDragAction) ||
                    (cardStack.type == CardStackType.Full && CurrentDragPhase == DragPhase.Begin) ||
                    (cardStack.type == CardStackType.Vertical && isOutXBounds) ||
                    (cardStack.type == CardStackType.Horizontal && isOutYBounds) ||
                    (cardStack.type == CardStackType.Area &&
                     (isOutYBounds || (PlaceHolder != null && PlaceHolder.parent != transform.parent))))
                {
                    ParentToCanvas(targetPosition);
                }
            }
        }