public ItemDisplay GenItem(int index) { ItemDisplay newitem = Instantiate <ItemDisplay>(Prefab_item); newitem.transform.SetParent(this.transform); newitem.inventory = this.GetComponent <InventoryDisplay>(); UpdateItem(newitem, index); newitem.UpdateItemDisplay(); return(newitem); }
public override void OnInspectorGUI() { ItemDisplay itemDisplay = (ItemDisplay)target; DrawDefaultInspector(); if (GUILayout.Button("Load Item Display")) { itemDisplay.UpdateItemDisplay(); } if (GUILayout.Button("Unload Item Display")) { itemDisplay.ResetItemDisplay(); } }
public void UpdateInventory() { items = inventory.itemsOwn; itemcount = items.Count; Dictionary <ItemType, int> .Enumerator en = items.GetEnumerator(); if (this.transform.childCount > itemcount) { for (int i = itemcount; i < this.transform.childCount; i++) { Debug.Log("destroying child:----" + i); Transform child = this.transform.GetChild(i); GameObject.Destroy(child.gameObject); } } for (int i = 0; i < itemcount; i++) { if (en.MoveNext()) { if (this.transform.childCount <= i) { ItemDisplay item = GenItem(i); item.type = en.Current.Key; item.num = en.Current.Value; item.UpdateItemDisplay(); } else { ItemDisplay item = this.transform.GetChild(i).GetComponent <ItemDisplay>(); item.type = en.Current.Key; item.num = en.Current.Value; item.UpdateItemDisplay(); } } } this.transform.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, (itemcount <= 12?3:(itemcount) / 4 + 1) * height * UnityEngine.Screen.height); }