public void EmptySlot()
 {
     stack = null;
     if (uiItemSlot != null)
     {
         uiItemSlot.UpdateSlot();
     }
 }
Ejemplo n.º 2
0
 public int Take(int amount)
 {
     if (amount >= stack.amount)
     {
         amount = stack.amount;
         EmptySlot();
     }
     else if (amount < stack.amount)
     {
         stack.amount -= amount;
         ui.UpdateSlot();
     }
     return(amount);
 }
Ejemplo n.º 3
0
    public void PutInItem(GameObject item)
    {
        string itemId = item.name;

        foreach (var door in doors)
        {
            if (door.SetHasKey(itemId) == true)
            {
                item.SetActive(false);
            }
        }

        switch (itemId)
        {
        case "Item-Key":
            item.SetActive(false);
            break;
        }
        Image      itemImg = item.GetComponent <Image>();
        GameObject slotObj = Instantiate(itemSlotPrefab, inventory); // gameobject를 만드는 함수

        RectTransform slotTrans = slotObj.GetComponent <RectTransform>();

        slotTrans.anchoredPosition = new Vector2(0f, 0f);      //RectTransform 에서 화면 정렬하는 기능을 사용하기 위한 함수

        UIItemSlot slot = slotObj.GetComponent <UIItemSlot>(); // C# scripts component

        slot.UpdateSlot(itemImg.sprite);
    }
Ejemplo n.º 4
0
    private void HandleSlotClick(UIItemSlot clicked, bool leftClk)
    {
        if (clicked == null)
        {
            return;
        }

        ItemSlot  clk_slot    = clicked.itemSlot;
        ItemStack cursorStack = cursorItemSlot.stack;
        bool      cursorHas   = cursorSlot.HasItem,
                  clickedHas  = clicked.HasItem;

        //  isCreative = clickedHas ? clk_slot.isCreative : false;

        if ((cursorStack == null || cursorStack.amount == 0) && clickedHas)
        {
            cursorStack = new ItemStack(clk_slot.stack.itemID, 0);
        }

        if (cursorHas)
        {
            if (!clickedHas)
            {
                clk_slot.stack = new ItemStack(cursorStack, true);
            }
            if (leftClk)
            {
                cursorStack = clk_slot.LeaveAll(cursorStack);
            }
            else
            {
                cursorStack = clk_slot.LeaveOne(cursorStack);
            }
        }
        else
        {
            if (clickedHas)
            {
                if (leftClk)
                {
                    cursorStack = clk_slot.TakeAll(cursorStack);
                }
                else
                {
                    cursorStack = clk_slot.TakeHalf(cursorStack);
                }
            }             // else return;
        }
        cursorItemSlot.stack = cursorStack;
        cursorSlot.UpdateSlot();
    }
Ejemplo n.º 5
0
 public void EmptySlot()
 {
     stack      = null;
     isCreative = false;
     if (uiItemSlot != null)
     {
         uiItemSlot.UpdateSlot();
     }
 }
Ejemplo n.º 6
0
 void HandleSlotClick(UIItemSlot clickedSlot)
 {
     if (clickedSlot == null)
     {
         return;
     }
     if (!cursorSlot.HasItem && !clickedSlot.HasItem)
     {
         return;
     }
     if (clickedSlot.itemSlot.isCreative)
     {
         cursorItemSlot.EmptySlot();
         cursorItemSlot.InsertStack(clickedSlot.itemSlot.stack);
     }
     if (!cursorSlot.HasItem && clickedSlot.HasItem)
     {
         cursorItemSlot.InsertStack(clickedSlot.itemSlot.TakeAll());
         cursorSlot.UpdateSlot();
         return;
     }
     if (cursorSlot.HasItem && !clickedSlot.HasItem)
     {
         clickedSlot.itemSlot.InsertStack(cursorItemSlot.TakeAll());
         clickedSlot.UpdateSlot();
         return;
     }
     if (cursorSlot.HasItem && clickedSlot.HasItem)
     {
         if (cursorSlot.itemSlot.stack.id != clickedSlot.itemSlot.stack.id)
         {
             ItemStack oldCursorSlot = cursorSlot.itemSlot.TakeAll();
             ItemStack oldSlot       = clickedSlot.itemSlot.TakeAll();
             clickedSlot.itemSlot.InsertStack(oldCursorSlot);
             cursorSlot.itemSlot.InsertStack(oldSlot);
         }
     }
 }
Ejemplo n.º 7
0
    public void PutInItem(GameObject item)
    {
        string itemId = item.name;

        foreach (var door in doors)
        {
            if (door.SetHasKey(itemId) == true)
            {
                item.SetActive(false);
            }
        }

        Image      itemImg = item.GetComponent <Image>();
        GameObject slotObj = Instantiate(itemSlotPrefab, inventory);

        RectTransform slotTrans = slotObj.GetComponent <RectTransform>();

        slotTrans.anchoredPosition = new Vector2(0f, 0f);

        UIItemSlot slot = slotObj.GetComponent <UIItemSlot>();

        slot.UpdateSlot(itemImg.sprite);
    }
Ejemplo n.º 8
0
    public void EmptySlot()
    {
        stack = null;

        ui?.UpdateSlot();
    }
Ejemplo n.º 9
0
 public void InsertStack(ItemStack _stack)
 {
     stack = _stack;
     uIItemSlot.UpdateSlot();
 }