Beispiel #1
0
    // Populate cards, reusing old card containers where possible.
    private void PopulateCards()
    {
        IEnumerable <string> cards = behaviorSystem.GetCards();
        int cardCount = cards.Count();

        // If we have more cards in the model than the UI, create the extra # of objects we need.
        for (int i = cardContainerObjects.Count; i < cardCount; i++)
        {
            CreateCardAndContainer();
        }

        // If we have more cards in the UI than the model, destroy the # of objects we don't need.
        for (int i = cardContainerObjects.Count - 1; i >= cardCount; i--)
        {
            GameObject containerObj = cardContainerObjects[i];
            Card       card         = containerObj.GetComponentInChildren <CardContainer>().GetCard();
            if (card != null)
            {
                Destroy(card.gameObject);
            }
            Destroy(containerObj);
            cardContainerObjects.RemoveAt(i);
        }

        // Populate the objects with the models.
        int j = 0;

        foreach (string cardUri in cards)
        {
            GameObject containerObj = cardContainerObjects[j];
            PopulateContainerWithUri(containerObj, cardUri);
            j++;
        }
    }