Exemplo n.º 1
0
 void OnDestroy()
 {
     while (items != null && items.Count > 0)
     {
         SaladIngredientCanvasScript ingredient = items.Dequeue();
         if (ingredient != null)
         {
             Destroy(ingredient.gameObject);
         }
     }
 }
Exemplo n.º 2
0
    /// <summary>
    /// Refreshes and recreates inventory data of player
    /// </summary>
    public void inventoryRefresh()
    {
        if (playerInventory == null)
        {
            return;
        }
        int[] items = playerInventory.getItemsInArray();
        while (inventoryPanel.transform.childCount != 0)
        {
            GameObject go = inventoryPanel.transform.GetChild(0).gameObject;
            go.transform.SetParent(null);
            Destroy(go);
        }

        if (reverseInventory)
        {
            Array.Reverse(items);
        }

        foreach (int item in items)
        {
            if (Vegetables.isRawVegetable(item))
            {
                GameObject go = Instantiate(vegItemIconPrefab);
                SaladIngredientCanvasScript saladIngredient = go.GetComponent <SaladIngredientCanvasScript>();
                saladIngredient.itemImageSprite.sprite = ChefSaladManager.getVegetableData(item).vegTexture;
                go.transform.SetParent(inventoryPanel.transform);
            }
            else
            {
                GameObject        go          = Instantiate(saladItemIconPrefab);
                SaladCanvasScript saladCanvas = go.GetComponent <SaladCanvasScript>();
                go.transform.SetParent(inventoryPanel.transform);
                int itemMask = item;
                for (int i = 0; i < (int)Vegies.count; i++)
                {
                    if ((itemMask & 1) > 0)
                    {
                        int veg = (int)Mathf.Pow(2, i);
                        saladCanvas.addItem(ChefSaladManager.getVegetableData(veg));
                    }
                    itemMask >>= 1;
                }
            }
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Adds a vegetable to salad
    /// </summary>
    /// <param name="vegData">Vegetable data of vegetable being added</param>
    /// <returns>true if added successfully.</returns>
    public bool addItem(VegetableData vegData)
    {
        if (items.Count == 0)
        {
            // If Queued Item icons are used already then return as this means ingredient count reached max(this case won't happen)
            // ,else fill it manually
            if (itemsContainerWidget.transform.childCount > 0)
            {
                return(false);
            }
            else
            {
                // This needs to be done as in some cases after spawn start gets executed only in
                // next frame and we need it in same frame.
                fillQueue();
            }
        }
        SaladIngredientCanvasScript item = items.Dequeue();

        item.itemImageSprite.sprite = vegData.vegTexture;
        item.transform.SetParent(itemsContainerWidget.transform);
        return(true);
    }