Example #1
0
    /// <summary>
    /// デッキ一覧の中から指定したデッキを現在のデッキに表示する
    /// </summary>
    /// <param name="button"></param>
    public void SetActiveDeck(DeckButton button)
    {
        if (currentDeckButton != null)
        {
            currentDeckButton.SetActive(false);
        }
        currentDeckButton = button;
        //ボタンの見た目を活性化する
        currentDeckButton.SetActive(true);

        //デッキの名前を既存のデッキ名に設定
        deckNameInputField.text = currentDeckButton.deck.name;

        //foreach(変数宣言 in 配列名)CardListItem中の各要素に対して1回ずつ処理が行われる。
        foreach (var item in cardListContent.GetComponentsInChildren <CardListItem>())
        {
            Destroy(item.gameObject);
        }
        //デッキ内のカード全てに対して実行
        foreach (var card in currentDeckButton.deck.cards)
        {
            //全てのカードデータを読み込む
            var libraryCard = GameManager.Instance.config.GetCard(card.id);
            //↓以下2行、Instantiate(cardListItemPrefab,cardListContent.transform, false)と同義
            var go = Instantiate(cardListItemPrefab) as GameObject;
            go.transform.SetParent(cardListContent.transform, false);
            //↑ここまで↑

            //全てのGameObjectの中からCardListItemを検索し、それぞれの変数に代入する
            //現在のデッキボタン情報を取得
            go.GetComponent <CardListItem>().deckButton = currentDeckButton;
            //構築中のデッキを表現する
            go.GetComponent <CardListItem>().card = libraryCard;
            go.GetComponent <CardListItem>().cardNameText.text   = libraryCard.name;
            go.GetComponent <CardListItem>().cardAmountText.text = "x" + card.amount.ToString();
            go.GetComponent <CardListItem>().count = card.amount;
            //costに対し全検索をかけて、最初にPayResourceCost型に一致したx(マナの値)を返す
            var cost = libraryCard.costs.Find(x => x is PayResourceCost);
            if (cost != null)
            {
                var payResourceCost = cost as PayResourceCost;
                var manaCost        = payResourceCost.value;
                go.GetComponent <CardListItem>().cardCostText.text = manaCost.ToString();
            }
        }
        //カードの枚数を表示
        UpdateNumCardsText();
    }
Example #2
0
    public void SetActiveDeck(DeckButton button)
    {
        if (currentDeckButton != null)
        {
            currentDeckButton.SetActive(false);
        }
        currentDeckButton = button;
        currentDeckButton.SetActive(true);

        deckNameInputField.text = currentDeckButton.deck.name;

        foreach (var item in cardListContent.GetComponentsInChildren <CardListItem>())
        {
            Destroy(item.gameObject);
        }

        foreach (var card in currentDeckButton.deck.cards)
        {
            var libraryCard = GameManager.Instance.config.GetCard(card.id);
            var go          = DeterminDeckIcon(libraryCard, GameManager.Instance.config);
            go.transform.SetParent(cardListContent.transform, false);
            go.GetComponent <CardListItem>().deckButton          = currentDeckButton;
            go.GetComponent <CardListItem>().card                = libraryCard;
            go.GetComponent <CardListItem>().cardNameText.text   = libraryCard.name;
            go.GetComponent <CardListItem>().cardAmountText.text = "x" + card.amount.ToString();
            go.GetComponent <CardListItem>().count               = card.amount;
            var cost = libraryCard.costs.Find(x => x is PayResourceCost);
            if (cost != null)
            {
                var payResourceCost = cost as PayResourceCost;
                var manaCost        = payResourceCost.value;
                go.GetComponent <CardListItem>().cardCostText.text = manaCost.ToString();
            }
        }

        UpdateNumCardsText();
    }