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("满了"); }
public static Sprite GetItemImgByType(Var.ItemType type) { return(GetImgByPath(itemImgPath + type.ToString())); }
public static GameObject GetItemInSceneByType(Var.ItemType type) { return(GetGameObjectByPath(itemInScenePath + type.ToString())); }