//! Destroy Item from the game. /*! Receives and item from the UI, removes it from the list and then destroy it from the scene. */ public void DestroyItem(ItemStackableBehavior itemUI) { AnyObjectInstantiation obj = itemUI.getObject(); RemoveItem(itemUI); Destroy(obj.gameObject); }
//! Add Item to inventory. /*! Receives and item and defines this inventory to it, also add this item to the interface using InventoryContent * and disable the original object from the scene. */ public void AddItem(AnyObjectInstantiation item) { item.SetInventory(this); tempItem = item; itens.Add(tempItem); requestAddItem = true; // item on scene will disappear item.gameObject.SetActive(false); }
// TODO: Verificar a real necessidade de colocar as funcoes dentro Update sendo chamadas atraves de variaveis booleanas. void Update() { // Check if an Item needs to be added or removed. if (requestAddItem) { requestAddItem = false; // content.addNewItemUI(tempItem); tempItem = null; } if (requestRemoveItem) { requestRemoveItem = false; content.removeItemUI(tempItemUI); tempItem = null; } }
//! Add New Item to Inventory UI /*! Receives an item, defines it's position inside the grid layout, instantiates a new prefab with the item's properties * at the position defined.*/ public void addNewItemUI(AnyObjectInstantiation item) { // if there is freedPosition, use it. If NOT, use the last item position. //prefabItem.GetComponent<AnyObjectInstantiation>().copyItemBase(item); // Debug.Log("Adding " + item.name // + " to " + 1 // + " at " + transform.parent.transform.parent.transform.parent.name); // find x and y for position float y = (prefabRect.rect.height + y_Offset) * lastItemPos; // set position Vector3 currentPos = new Vector3(1f, -60 - 110 * (lastItemPos)); // add content size to fit more items contentRect.sizeDelta = new Vector2( 1f, // width doesnt change 120 + (prefabRect.rect.height + y_Offset) * lastItemPos); // instantiate Item GameObject tempItem = Instantiate(prefabItem.gameObject, currentPos, prefabItem.transform.rotation) as GameObject; // next position on inventory grid lastItemPos++; // set new item parent to scroll rect content //tempItem.GetComponent<Image>().sprite = item.icon; tempItem.transform.SetParent(contentRect.transform, false); tempItem.name = item.name + "_" + 1; tempItem.GetComponent <ItemStackableBehavior>().setObject(item); }
//! Set linked object to AnyObjectInstantiation. public void setObject(AnyObjectInstantiation i) { this.linkedObject = i; }