public void PutIntoWorkshopInventory()
    {
        bool       updated  = false;
        GameObject heldItem = ItemDragHandler.heldItem;

        Components.ItemName heldItemName = heldItem.GetComponent <WorkshopShipComponent>().itemName;
        foreach (Transform itemSlot in transform)
        {
            WorkshopShipComponent component = itemSlot.GetComponentInChildren <WorkshopShipComponent>();
            if (component != null && component.itemName.Equals(heldItemName))
            {
                int quantity = int.Parse(itemSlot.GetComponentInChildren <Text>().text) + 1;
                itemSlot.GetComponentInChildren <Text>().text = quantity.ToString();
                Destroy(heldItem);
                updated = true;
                break;
            }
        }

        if (!updated)
        {
            foreach (Transform itemSlot in transform)
            {
                WorkshopShipComponent component = itemSlot.GetComponentInChildren <WorkshopShipComponent>();
                if (component == null)
                {
                    heldItem.transform.SetParent(itemSlot);
                    heldItem.transform.localPosition = Vector3.zero;
                    heldItem.GetComponent <CanvasGroup>().blocksRaycasts = true;
                    itemSlot.GetComponentInChildren <Text>().text        = "1";
                    break;
                }
            }
        }
    }
Ejemplo n.º 2
0
 void Update()
 {
     if (Input.GetMouseButtonUp(0))
     {
         if (installedItem != null && !Item)
         {
             inventory.UninstallComponent(installedItem.itemName);
             installedItem = null;
         }
     }
 }
Ejemplo n.º 3
0
 public void OnDrop(PointerEventData eventData)
 {
     if (!Item)
     {
         GameObject          heldItem     = ItemDragHandler.heldItem;
         Components.ItemName heldItemName = heldItem.GetComponent <WorkshopShipComponent>().itemName;
         if (installableItems.Contains(heldItemName))
         {
             heldItem.transform.SetParent(transform);
             Item.transform.localPosition = Vector3.zero;
             inventory.InstallComponent(heldItemName);
             installedItem = heldItem.GetComponent <WorkshopShipComponent>();
         }
     }
 }