Exemplo n.º 1
0
 void OnCraft(CraftingFormula formula)
 {
     if (null != formula)
     {
         inventory.Craft(formula);
     }
 }
Exemplo n.º 2
0
    void AddCraftableItem(CraftingFormula formula)
    {
        var item = Instantiate(prefab);

        item.transform.SetParent(content, false);
        list.Add(item);

        item.transform.localPosition = new Vector3(0, -itemHeight * (list.Count - 1));

        item.Formula = formula;

        content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, itemHeight * list.Count);
    }
Exemplo n.º 3
0
    /// <summary>
    /// Craft an item
    /// </summary>
    /// <param name="item">Item to craft</param>
    /// <returns>Returns if crafting was successful</returns>
    public bool Craft(CraftingFormula formula)
    {
        if (null == formula || !formula.Valid())
        {
            return(false);
        }

        var mat1 = FindItemByName(formula.material1);
        var mat2 = FindItemByName(formula.material2);
        var mat3 = FindItemByName(formula.material3);

        if (null == mat1 || null == mat2 || null == mat3)
        {
            return(false);
        }

        Remove(mat1);
        Remove(mat2);
        Remove(mat3);
        Add(formula.result.Generate());

        return(true);
    } //end of craft