Beispiel #1
0
    void Update()
    {
        //If Player selected chest with a cursor.
        if (UIManager.Instance.nowInteractTarget == this)
        {
            if (!isOpened)
            {
                if (Input.GetKeyDown(KeyCode.E))
                {
                    Open();
                }
            }
        }

        if (isOpened)
        {
            if (Input.GetMouseButtonDown(0))
            {
                InventoryEventSystem.CheckCursorInput();
            }

            if (Input.GetKeyDown(KeyCode.Escape) || Vector2.Distance(PlayerController.Instance.transform.position, transform.position) > radToInteract)
            {
                Close();
            }
        }
    }
Beispiel #2
0
    // When player clicks at hotkey (hotbar area) invGear adds to inventory and vice versa
    public static void CheckCursorInput()
    {
        List <RaycastResult> raycastedData = UIRaycast();

        if (raycastedData.Count == 0)
        {
            return;
        }

        RaycastResult raycast;

        raycast = raycastedData.FirstOrDefault(x => x.gameObject.CompareTag("Hotkey"));
        // If clicks at hotkey
        if (raycast.gameObject != null)
        {
            Hotkey nowHK = raycast.gameObject.GetComponent <Hotkey>();

            InventorySlot emptyInvSlot = UIManager.Instance.inventory.invSlots.FirstOrDefault(x => x.invGear == null);

            // Changing first empty invSlot data taken from nowHK
            if (nowHK.invGear != null)
            {
                emptyInvSlot.invGear = nowHK.invGear;

                //Updating Data
                UIManager.Instance.inventory.UpdateSlotData(emptyInvSlot, nowHK.invGear);
                UIManager.Instance.hotbar.UpdateHotkeyData(nowHK, null);
            }

            InventoryEventSystem.ReplaceGear();

            Debug.Log("Clicked at hotkey");
            return;
        }

        raycast = raycastedData.FirstOrDefault(x => x.gameObject.CompareTag("InvSlot"));
        // If clicks at inventory slot
        if (raycast.gameObject != null)
        {
            InventorySlot invSlot = raycast.gameObject.GetComponent <InventorySlot>();

            Hotkey emptyHK = UIManager.Instance.hotbar.hotkeys.FirstOrDefault(x => x.invGear == null);

            // Changing first empty hotkey data taken from invSlot
            if (invSlot.invGear != null)
            {
                emptyHK.invGear = invSlot.invGear;

                //Updating Data
                UIManager.Instance.hotbar.UpdateHotkeyData(emptyHK, invSlot.invGear);
                UIManager.Instance.inventory.UpdateSlotData(invSlot, null);
            }

            InventoryEventSystem.ReplaceGear();

            Debug.Log("Clicked at inventory slot");
            return;
        }
    }
Beispiel #3
0
    void Craft(BlueprintData bp_Data)
    {
        SpendResources(bp_Data.resourcePrices);
        DeleteUIItem(bp_Data);

        InventoryEventSystem.AddGearToInventory(bp_Data.gearData);
        InventoryEventSystem.ReplaceGear();
    }
Beispiel #4
0
 void SelectKey()
 {
     for (int i = 0; i < hotkeys.Length; i++)
     {
         if (i == selectedKey)
         {
             hotkeys[i].bg.color = selectedColor;
         }
         else
         {
             hotkeys[i].bg.color = unselectedColor;
         }
     }
     InventoryEventSystem.ReplaceGear();
 }