/// <summary>
        /// Check if player can set toolbar target to selected cell
        /// </summary>
        /// <param name="index">Toolbar cell index</param>
        /// <param name="cell">Inventory cell</param>
        /// <param name="toolbarCell">if true returns selected cell</param>
        /// <returns></returns>
        public static bool CanSetToolbarItem(int index, InventoryCellUI cell, out ToolbarCellUI toolbarCell)
        {
            toolbarCell = null;
            if (index < 0 || index >= Instance.toolbarCells.Length || cell.item == null)
            {
                return(false);
            }

            toolbarCell = Instance.toolbarCells[index];

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Handle player's input
        /// </summary>
        public void HandleInput()
        {
            if (CameraController.isLooking)
            {
                return;
            }

            if (!CursorController.IsCursorOverUI())
            {
                if (Input.GetButtonDown("Move"))
                {
                    movementClickCooldown = 0;
                }

                if (Input.GetButton("Move") && movementClickCooldown <= 0)
                {
                    RaycastHit hit;
                    Ray        ray = m_Camera.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(ray, out hit, Mathf.Infinity, moveLayerMask))
                    {
                        positionSynchronization.CmdSetDestination(hit.point);
                    }
                    target = null;

                    movementClickCooldown = 0.25f;
                }
                if (Input.GetButtonDown("Attack") && usedWeapon)
                {
                    RaycastHit hit;
                    Ray        ray = m_Camera.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(ray, out hit) && (hit.transform.tag == "Player" || hit.transform.tag == "Entity"))
                    {
                        float  distance = Vector3.Distance(transform.position, hit.transform.position);
                        Entity entity   = hit.transform.GetComponent <Entity>();

                        if (distance < usedWeapon.attackRange)
                        {
                            SetTarget(entity);
                        }
                        else
                        {
                            SetTarget(entity);
                            SetDestinationToEntity(entity);
                        }
                    }
                }
            }

            if (Input.GetButtonDown("ClosestEnemy"))
            {
                target = GetClosestEntity();
            }

            #region //======    TOOLBAR    ======\\

            for (int i = 1; i <= 9; i++)
            {
                if (Input.GetButtonDown("Toolbar" + i))
                {
                    ToolbarCellUI toolbarCell = InventorySystem.GetToolbarCell(i - 1);
                    if (toolbarCell & toolbarCell.Cell)
                    {
                        toolbarCell.Cell.item.UseItem(new Vector2Byte(toolbarCell.Cell.indexPosition));
                    }
                }
            }

            #endregion

            if (Input.GetKeyDown(KeyCode.E))
            {
                ItemData data = new ItemData(0, 15);
                CmdAddItem(data);
            }
        }