public void OnPointerEnter(PointerEventData eventData) { // Populate text box with item details if (itemQuantity != 0) { // Instantiate inventory text box inventoryBar.inventoryTextBoxGameobject = Instantiate(inventoryTextBoxPrefab, transform.position, Quaternion.identity); inventoryBar.inventoryTextBoxGameobject.transform.SetParent(parentCanvas.transform, false); UIInventoryTextBox inventoryTextBox = inventoryBar.inventoryTextBoxGameobject.GetComponent<UIInventoryTextBox>(); // Set item type description string itemTypeDescription = InventoryManager.Instance.GetItemTypeDescription(itemDetails.itemType); // Populate text box inventoryTextBox.SetTextboxText(itemDetails.itemDescription, itemTypeDescription, "", itemDetails.itemLongDescription, "", ""); // Set text box position according to inventory bar position if (inventoryBar.IsInventoryBarPositionBottom) { inventoryBar.inventoryTextBoxGameobject.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0f); inventoryBar.inventoryTextBoxGameobject.transform.position = new Vector3(transform.position.x, transform.position.y + 50f, transform.position.z); } else { inventoryBar.inventoryTextBoxGameobject.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f); inventoryBar.inventoryTextBoxGameobject.transform.position = new Vector3(transform.position.x, transform.position.y - 50f, transform.position.z); } } }
// This method will be triggered when the users pointer enters the game object this script is on (inventorySlots 0...47) public void OnPointerEnter(PointerEventData eventData) { // Populate the text box with the item details, as long as there is an actual item there (i.e. if itemQuantity is not 0) if (itemQuantity != 0) { // Instantiate the inventoryBar's inventoryTextBoxGameObject with the text box prefab, parented to the same parent all the slot UIs live under! inventoryManagement.inventoryTextBoxGameObject = Instantiate(inventoryTextBoxPrefab, transform.position, Quaternion.identity); inventoryManagement.inventoryTextBoxGameObject.transform.SetParent(parentCanvas.transform, false); UIInventoryTextBox inventoryTextBox = inventoryManagement.inventoryTextBoxGameObject.GetComponent <UIInventoryTextBox>(); // Set the item type description string itemTypeDescription = InventoryManager.Instance.GetItemTypeDescription(itemDetails.itemType); // Populate the text box with the item descriptions, using the method in UIInventoryTextBox, taking in top1, top2, top3, bottom1, bottom2, bottom3 inventoryTextBox.SetTextBoxText(itemDetails.itemDescription, itemTypeDescription, "", itemDetails.itemLongDescription, "", ""); // Set text box position according the row of items we are accessing if (slotNumber > 23) { // If we are checking items in the bottom two rows, set the pivot to the bottom of the text box, and 50 pixels above the inventory bar inventoryManagement.inventoryTextBoxGameObject.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 0f); inventoryManagement.inventoryTextBoxGameObject.transform.position = new Vector3(transform.position.x, transform.position.y + 50f, transform.position.z); } else { // If we are checking items in the top two rows, set the pivot to the top of the text box, and 50 pixels below the inventory bar inventoryManagement.inventoryTextBoxGameObject.GetComponent <RectTransform>().pivot = new Vector2(0.5f, 1f); inventoryManagement.inventoryTextBoxGameObject.transform.position = new Vector3(transform.position.x, transform.position.y - 50f, transform.position.z); } } }