Example #1
0
    void handleMouseClick(int quantity)
    {
        if (!init)
        {
            if (MoleController.localPlayer.GetComponent <Player> ().info.cursorSlot == null)
            {
                return;
            }
            localPlayer = MoleController.localPlayer.GetComponent <Player> ();
            cursorSlot.setSlotBackingInfo(MoleController.localPlayer.GetComponent <Player> ().info.cursorSlot);
            init = true;
        }



        PointerEventData pointerData = new PointerEventData(EventSystem.current);

        pointerData.position = Input.mousePosition;

        cursorSlot.setSlotBackingInfo(localPlayer.info.cursorSlot);

        List <RaycastResult> results = new List <RaycastResult> ();

        EventSystem.current.RaycastAll(pointerData, results);

        foreach (RaycastResult r in results)
        {
            if (r.gameObject.name.Equals("SlotUIBackground"))
            {
                ItemInventorySlotUI slotUI = r.gameObject.GetComponentInParent <ItemInventorySlotUI>();
                if (slotUI != null)
                {
                    string[] splitName      = slotUI.gameObject.name.Split(' ');
                    string   menuIdentifier = splitName [0];
                    string   slotIdentifier = splitName [1];


                    //pickup half stack if right click
                    if (cursorSlot.getSlotBackingInfo().isEmpty() && quantity == 1)
                    {
                        quantity = Mathf.CeilToInt(slotUI.getSlotBackingInfo().getQuantity() / 2.0f);
                    }

                    handleSlotSelect(slotUI, menuIdentifier, slotIdentifier, quantity);
                    return;
                }
            }
            return;                                //If clicking on a UI component at all, don't drop item. Must explicitly be dropping on game area
        }
        handleSlotSelect(null, "", "0", quantity); //drop items in cursor
    }
Example #2
0
    public void loadInventory(Inventory inventory)
    {
        if (inventory == null)
        {
            return;
        }
        destroySlotUIs();
        this.inventory = inventory;

        RectTransform r = GetComponent <RectTransform> ();

        ItemInventorySlot[] slotBackings = inventory.getSlots();
        dist_between_slots = r.rect.width / slotBackings.Length;
        startingX          = r.rect.xMin + dist_between_slots / 2;

        slots = new ItemInventorySlotUI [slotBackings.Length];
        for (int i = 0; i < slotBackings.Length; i++)
        {
            GameObject iconObj = GameObject.Instantiate(inventorySlotPrefab, GetComponent <Transform> ());
            iconObj.name = "BeltSlot " + i;
            RectTransform iconTrans = iconObj.GetComponent <RectTransform> ();
            iconTrans.localPosition = new Vector2(startingX + dist_between_slots * i, r.rect.center.y);
            ItemInventorySlotUI slot = iconObj.GetComponent <ItemInventorySlotUI> ();
            slot.setSlotBackingInfo(slotBackings[i]);
            slots [i] = slot;
        }
        updateUI();
        selecticle.SetAsLastSibling();
    }
Example #3
0
    void buildSlots()
    {
        if (inventory == null)
        {
            return;
        }

        ItemInventorySlot[] slotBackings = inventory.getSlots();
        slots = new ItemInventorySlotUI[slotBackings.Length];

        for (int i = 0; i < slots.Length; i++)
        {
            int col = i % NUM_SLOTS_WIDTH;
            int row = i / NUM_SLOTS_WIDTH;

            GameObject iconObj = GameObject.Instantiate(inventorySlotPrefab, GetComponent <Transform> ());
            iconObj.name = "BackpackSlot " + i;
            RectTransform iconTrans = iconObj.GetComponent <RectTransform> ();
            iconTrans.localPosition = slotSeed.localPosition + new Vector3(slotSeed.rect.size.x * col, slotSeed.rect.size.y * row);
            ItemInventorySlotUI slot = iconObj.GetComponent <ItemInventorySlotUI> ();
            slot.setSlotBackingInfo(slotBackings[i]);
            slots [i] = slot;
        }
    }