コード例 #1
0
    public void AddItem(Var.ItemType type, int num)
    {
        foreach (ItemData o in bagItems)
        {
            if (o.itemType.Equals(type))
            {
                o.itemNum   += num;
                o.numChanged = true;
                return;
            }
        }
        for (int i = 0; i < EquipNum; i++)
        {
            GameObject o = equipObj.transform.GetChild(i).gameObject;
            if (o.transform.childCount == 1)
            {
                Type       classType = Tools.ReturnTypeByStr(type.ToString());
                GameObject go        = Instantiate(bagItem, Vector3.zero, equipObj.transform.rotation) as GameObject;
                go.transform.SetParent(o.transform);
                go.transform.SetAsFirstSibling();
                go.AddComponent(classType);
                go.transform.localScale = Vector3.one;
                go.GetComponent <BagItem>().Initial(type, num, i);
                bagItems.Add(go.GetComponent <BagItem>().itemData);
                return;
            }
        }


        for (int i = 0; i < bagSize; i++)
        {
            GameObject o = bagObj.transform.GetChild(i).gameObject;
            if (o.transform.childCount == 0)
            {
                Type       classType = Tools.ReturnTypeByStr(type.ToString());
                GameObject go        = Instantiate(bagItem, Vector3.zero, bagObj.transform.rotation) as GameObject;
                go.transform.SetParent(o.transform);
                go.AddComponent(classType);
                go.transform.localScale = Vector3.one;
                go.GetComponent <BagItem>().Initial(type, num, i + EquipNum);
                bagItems.Add(go.GetComponent <BagItem>().itemData);
                return;
            }
        }

        Debug.Log("满了");
    }
コード例 #2
0
ファイル: Tools.cs プロジェクト: Fuinaru/Game
 public static Sprite GetItemImgByType(Var.ItemType type)
 {
     return(GetImgByPath(itemImgPath + type.ToString()));
 }
コード例 #3
0
ファイル: Tools.cs プロジェクト: Fuinaru/Game
 public static GameObject GetItemInSceneByType(Var.ItemType type)
 {
     return(GetGameObjectByPath(itemInScenePath + type.ToString()));
 }