Esempio n. 1
0
    public void SetupCells()
    {
        // Destroy all existing cells
        foreach (StoreItemCell cell in existingCells)
        {
            Destroy(cell.gameObject);
        }
        existingCells.Clear();

        // If game manager exists then instantiate a cell for each item
        if (GameManager.Instance)
        {
            // Select items with the given category
            IEnumerable <LevelData.ItemData> itemsWithCategory = GameManager.Instance.LevelData.itemQuantities
                                                                 .Where(item => item.itemObject.ItemID.Category == groupPicker.FirstValuePicked);

            // For each item, create a new cell, initialize it, and add it to the list
            foreach (LevelData.ItemData itemData in itemsWithCategory)
            {
                StoreItemCell cell = Instantiate(itemCellPrefab, cellParent);
                // Initialize the cell instance
                cell.Initialize(itemData.itemObject, true, itemClickedEvent.Invoke);
                cell.RemainingAmount = GameManager.Instance.m_resourceManager.CheckRemainingResource(itemData.itemObject);
                existingCells.Add(cell);
            }
        }
    }
Esempio n. 2
0
 public void setupItemSupplyTracker(StoreItemCell storeItem)
 {
     if (!itemDisplayInfo.ContainsKey(storeItem.item.ItemName))
     {
         itemDisplayInfo.Add(storeItem.item.ItemName, storeItem);
         storeItem.RemainingAmount = remainingResources[storeItem.item.ItemName];
     }
 }
Esempio n. 3
0
 void InstantiateItemsPrefabs()
 {
     //Instantiate power-ups
     for (int p = 0; p < Data.StorePowerups.Length; p++)
     {
         GameObject GO = Instantiate(ItemPrefab);
         GO.transform.SetParent(ItemsParent, false);
         StoreItemCell Cell = GO.GetComponent <StoreItemCell>();
         Cell.Initialize(this, Data.StorePowerups[p]);
     }
 }
Esempio n. 4
0
    /// <summary>
    /// Add item to the section.
    /// </summary>
    public void AddItem(Item item)
    {
        GameObject    newItemCellGO = Instantiate(itemCellPrefab, itemGrid);
        StoreItemCell itemCell      = newItemCellGO.GetComponent <StoreItemCell>();

        itemCell.Initialize(item, false, OnItemSelected);
        if (this.ResourceManager.hasLimitedSupply(item.ItemName))
        {
            this.ResourceManager.setupItemSupplyTracker(itemCell);
            if (!storeItems.ContainsKey(item))
            {
                storeItems.Add(item, itemCell);
            }
        }
    }
Esempio n. 5
0
    private ConditionalHighlight HighlightBuildItem <StoreSectionType>(ItemID item)
        where StoreSectionType : StoreSection
    {
        // Get the store section targetted
        StoreSectionType storeSection = GameManager.Instance.BuildUI.GetComponentInChildren <StoreSectionType>(true);

        // Get a list of all store item cells in the store section
        StoreItemCell[] cells = storeSection.GetComponentsInChildren <StoreItemCell>(true);
        // Find a cell in the list of all the cells that will be our target
        StoreItemCell target = Array.Find(cells, cell => cell.item.ItemID == item);
        // Convert the target transform to a rect transform
        RectTransform targetTransform = target.transform as RectTransform;

        // Return a highlight for the item cell with the given id
        return(new ConditionalHighlight()
        {
            predicate = () => storeSection.SelectedItem == null || storeSection.SelectedItem.ItemID != item,
            target = () => targetTransform
        });
    }