Example #1
0
 // sets cursor bool and gameobject to inactive
 void HideCursor()
 {
     SendName?.Invoke("");
     cursorHidden = true;
     CursorHidden?.Invoke();
     mainCursorImage.enabled = false;
 }
Example #2
0
    // applies horizontal axis rounded to a positive or negative of the move distance
    void MoveHorizontal(float xInput)
    {
        if (cursorHidden == false && cursorCoroutine == null)
        {
            cursorCoroutine = StartCoroutine(CursorDelayRoutine());

            // saves starting position, moves
            Vector3 startingPosition = transform.position;
            Vector3 translation      = new Vector3((xInput > 0 ? 1 : -1) * cursorSearchDistance, 0, 0);
            transform.Translate(translation);

            // calls raycast search to read an object the cursor is over
            bool foundItem = RaycastSearch(startingPosition);

            // if no item was found (meaning it moved horizontally off the item screen, moves it to the top slot in the far row and activates UI graphic
            if (foundItem == false)
            {
                // activates the r and z icons and sets the main cursor to inactive
                if (xInput > 0)
                {
                    menuUIControl.ActivateRIcon();
                }
                else if (xInput < 0)
                {
                    menuUIControl.ActivateZIcon();
                }

                // hides cursor
                moveAudio.Play();
                SendName?.Invoke("");
                HideCursor();
                CursorHidden?.Invoke();
            }
        }
    }
Example #3
0
    // raycasts the canvas object the cursor is over to determine how the cursor moves
    bool RaycastSearch(Vector3 position)
    {
        // moves pointer event data and fires a graphic raycast
        pointerEventData.position = Camera.main.WorldToScreenPoint(transform.position);
        List <RaycastResult> results = new List <RaycastResult>();

        graphicRaycaster.Raycast(pointerEventData, results);

        // if the raycast hits, saves current item, else returns cursor to starting position
        if (results.Count > 0)
        {
            if (results[0].gameObject.GetComponentInParent <MenuItem>() == true)
            {
                // stores reference to the item function
                currentItem = results[0].gameObject.GetComponentInParent <MenuItem>();

                // transforms cursor directly to the center of the found object, plays respective feedback
                transform.position = new Vector3
                                         (results[0].gameObject.transform.position.x, results[0].gameObject.transform.position.y, transform.position.z);
                moveAudio.Play();
                SendName?.Invoke(currentItem.itemName);
                return(true);
            }
            else if (results[0].gameObject.GetComponentInParent <MenuItem>() == false)
            {
                // returns cursor to previous transform position (effectively, it doesn't move)
                transform.position = position;
                return(false);
            }
        }
        else
        {
            // also reverts cursor position to check errors
            transform.position = position;
            return(false);
        }
        return(false);
    }