public void SetId(int id) { this.id = id; Texture2D tex = ItemStore.getItem(id).texture; image.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero); }
public void SlotClick() { EquipmentSlot slot = EventSystem.current.currentSelectedGameObject.GetComponent <EquipmentSlot>(); if (slot.GetCount() > 0 && !mouseImage.enabled) { Texture2D tex = ItemStore.getItem(slot.GetId()).texture; mouseImage.sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero); mouseImage.enabled = true; mouseId = slot.GetId(); mouseCount = slot.GetCount(); mouseText.text = mouseCount > 1 ? mouseCount.ToString() : ""; mouseSelected = selectedSlot == slot; slot.SetCount(0); slot.Deselect(); } else if (mouseImage.enabled && slot.GetCount() == 0) { mouseImage.enabled = false; slot.SetId(mouseId); slot.SetCount(mouseCount); mouseText.text = ""; if (mouseSelected) { slot.Select(); } } }
// Update the visual texture to comply with the texture of the item contained within this entity void updateVisuals() { ItemAsset asset = ItemStore.getItem(_itemID); Texture2D texture = asset.texture; Debug.Log("Asset " + asset.id + asset.name); _renderer.material.mainTexture = texture; }
void OnCollisionEnter2D(Collision2D other) { EntityPlayer entity = other.gameObject.GetComponent <EntityPlayer>(); // Is the entity we collided with a player? if (entity != null) { Debug.Log("Player"); // Store the item in the inventory (TEMPORARILY SET TO 99999) ItemAsset item = ItemStore.getItem(_itemID); entity.addItem(item.getItem(), 1); // TODO: // Pooling behaviour, NEVER destroy like this Destroy(gameObject); } }
void OnGUI() { if (_open) { GUI.skin = style; List <Stack> items = _inventory.items; //Nilupul // Draw the outlining window for the inventory GUI.BeginGroup(_windowRect, _background); GUI.EndGroup(); int x = 0; int y = 0; // Draw Main inventory window for (int i = 0; i < items.Count; i++) { if (x == _inventoryRowLength) { x = 0; y++; } Rect rect = new Rect(new Vector2(_windowRect.x + ((_spacingX + _buttonSize) * x), _windowRect.y + ((_spacingY + _buttonSize) * y)) + _inventoryOffset, new Vector2(_buttonSize, _buttonSize)); ItemAsset item = ItemStore.getItem(items[i].item.id); // Draw the blocks texture GUI.DrawTexture(rect, item.texture); // Draw the UI element if (GUI.Button(rect, "")) { _inventory.setActiveItem(i); } // Draw the selection square if (i == _inventory.activeIndex) { GUI.DrawTexture(rect, _selectionSquare); } // Draw the quantity GUI.Label(rect, "" + items[i].count); x++; } x = 0; y = 0; // Draw Crafting inventory window for (int i = 0; i < availableRecipies.Count; i++) { if (x == _craftingRowLength) { x = 0; y++; } Rect rect = new Rect(new Vector2(_windowRect.x + ((_spacingX + _buttonSize) * x), _windowRect.y + ((_spacingY + _buttonSize) * y)) + _craftingOffset, new Vector2(_buttonSize, _buttonSize)); ItemAsset item = availableRecipies[i]; // Draw the blocks texture GUI.DrawTexture(rect, item.texture); // Draw the UI element if (GUI.Button(rect, "")) { // Temporarily add 99999 of that specified item to the inventory _inventory.addItem(item.getItem(), 1); // Re-build any recipes which can be now created. rebuildRecipes(); } x++; } } }