Пример #1
0
        void init()
        {
            print("---init");

            UICtrl.instance.hideView();

            string           json          = File.ReadAllText("./Assets/Resources/cardBuild.json", Encoding.UTF8);
            List <CardBuild> cardBuildList = JsonConvert.DeserializeObject <List <CardBuild> > (json);

            List <Card> cardList = new List <Card> ();

            for (int i = 0; i < cardBuildList.Count; i++)
            {
                cardList.Insert(Random.Range(i, i + 1), cardBuildList[i]);
            }

            civilCardCtrls = new Queue <CardCtrl> ();
            cardList.ForEach(card => {
                CardCtrl newCtrdCtrl = Instantiate <CardCtrl> (cardCtrlPrefab, cardCtrlPrefab.transform.parent);
                newCtrdCtrl.card     = card;
                card.cardCtrl        = newCtrdCtrl;
                civilCardCtrls.Enqueue(newCtrdCtrl);
            });

            rowCardCtrls = new CardCtrl[rowCardLimitNum];
            // run ();
        }
Пример #2
0
        CardCtrl getANewCard()
        {
            if (civilCardCtrls.Count == 0)
            {
                return(null);
            }
            CardCtrl cardCtrl = civilCardCtrls.Dequeue();
            Card     card     = cardCtrl.card;

            Text[] texts = cardCtrl.GetComponentsInChildren <Text> ();
            Dictionary <string, Text> textDic = texts.ToDictionary(key => key.name, text => text);

            textDic["cardName"].text = card.cardName;
            if (card is CardBuild)
            {
                CardBuild cb = (CardBuild)card;
                textDic["costScience"].text = cb.cost.science.ToString();
            }
            return(cardCtrl);
        }