Example #1
0
    private IEnumerator LayDownCorutine(LayDownCorutineArgs args)
    {
        // Get real index [this is copied code, maybe use a function]
        if (args.fromIndex < 0)
        {
            args.fromIndex = _spots.Count - 1;
        }
        args.fromIndex = Mathf.Clamp(args.fromIndex, 0, _spots.Count);

        // Generate transform data
        List <TransformData> transformDatas = style.GetCardsTransformData(_spots.Count);

        // Start from the args.fromIndex, then gradually go to the cards on its side. Set the
        // transform of this cards by getting it from the deck style and the smoothly move them
        // using the smooth movements component
        int sideIndex = 0;

        while (sideIndex <= _spots.Count - 1)
        {
            if (sideIndex == 0)
            {
                // Initial card
                ApplyDeckStyleTransformToCard(args.fromIndex, transformDatas[args.fromIndex]);
            }
            else
            {
                if (args.fromIndex - sideIndex >= 0)
                {
                    // Card before
                    ApplyDeckStyleTransformToCard(args.fromIndex - sideIndex, transformDatas[args.fromIndex - sideIndex]);
                }
                if (args.fromIndex + sideIndex <= _spots.Count - 1)
                {
                    // Card after
                    ApplyDeckStyleTransformToCard(args.fromIndex + sideIndex, transformDatas[args.fromIndex + sideIndex]);
                }
            }

            sideIndex++;

            if (args.gradually)
            {
                yield return(new WaitForSeconds(_timeForGradually));
            }
        }

        // Set layer order (from the card component) again (or the z pos will be 0)
        // [TODO: DO NOT REPEAT]
        for (int i = 0; i < _spots.Count; i++)
        {
            // Set layer order (from the card component)
            TabletopCard tc = _spots[i].card.GetComponentInChildren <TabletopCard>();
            if (tc != null)
            {
                tc.SetLayerOrder(i);
            }
        }

        yield return(null);
    }
Example #2
0
    /// <summary>
    /// Laies down cards.
    /// </summary>
    /// <param name="fromIndex">First card to lay down. If <c>-1</c> the first card is the top one.</param>
    /// <param name="gradually">If set to <c>false</c> all cards are positioned at the same time.</param>
    public void LayDown(int fromIndex = 0, bool gradually = true)
    {
        UpdateDropAreas();

        // Stop if there is no deck style
        if (style == null)
        {
            Debug.Log("Cannot lay down cards of \"" + gameObject.name + "\": deck style missing.");
            return;
        }

        // Set correct z index before anything else
        for (int i = 0; i < _spots.Count; i++)
        {
            // Set layer order (from the card component)
            TabletopCard tc = _spots[i].card.GetComponentInChildren <TabletopCard>();
            if (tc != null)
            {
                tc.SetLayerOrder(i);
            }
        }

        // Apply transform
        LayDownCorutineArgs args;

        args.fromIndex = fromIndex;
        args.gradually = gradually;
        StopCoroutine("LayDownCorutine");
        StartCoroutine("LayDownCorutine", args);
    }