Ejemplo n.º 1
0
    /// <summary>
    /// 生成牌组
    /// </summary>
    public void CreateCardList()
    {
        if (this.cardPrefab == null)
        {
            return;
        }

        // 手牌总数不足则补充
        while (this.cardList.Count < GlobalManager.cardCount)
        {
            //Card card = CardsData.CreateRandomCard();
            CardsData data = CardsData.GetRandomData();
            if (data == null)
            {
                Debug.LogError("没有更多得牌库");
                return;
            }

            GameObject cardObject = Instantiate(this.cardPrefab);
            cardObject.transform.SetParent(cardListTransform);

            Card card = cardObject.GetComponent <Card>();
            //Card card = cardObject.AddComponent<Card>();
            data.SettingData(card);
            //this.cardList.Add(card);
        }

        for (int i = 0; i < this.cardList.Count; i++)
        {
            if (this.cardList[i] == null)
            {
                CardsData data = CardsData.GetRandomData();
                if (data == null)
                {
                    Debug.LogError("没有更多得牌库");
                    return;
                }

                GameObject cardObject = Instantiate(this.cardPrefab);
                cardObject.transform.SetParent(cardListTransform);

                Card card = cardObject.GetComponent <Card>();
                //Card card = cardObject.AddComponent<Card>();
                data.SettingData(card);
                this.cardList[i] = card;
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 创建卡牌
    /// </summary>
    /// <param name="_data"></param>
    /// <returns></returns>
    public Card CreateCard(CardsData _data)
    {
        if (this.cardPrefab == null)
        {
            return(null);
        }
        GameObject cardObject = Instantiate(this.cardPrefab);

        cardObject.transform.SetParent(cardListTransform);

        Card card = cardObject.GetComponent <Card>();

        //Card card = cardObject.AddComponent<Card>();
        _data.SettingData(card);

        return(card);
        //this.cardList[i] = card;
    }