Example #1
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        void Update()
        {
            if (Input.GetButtonDown("Fire1"))
            {
                var pointer = new PointerEventData(EventSystem.current);
                if (Input.touchSupported)
                {
                    pointer.position = Input.touches[0].position;
                }
                else
                {
                    pointer.position = Input.mousePosition;
                }
                var results = new List <RaycastResult>();
                EventSystem.current.RaycastAll(pointer, results);
                if (results.Count > 0)
                {
                    return; // user is clicking on a UI item
                }

                // Notify other objects that the "attack" button was pressed
                MessageBroker.Instance.Enqueue(Msg.ClientMsg(Msgs.CMD_INPUT_ATK, Msgs.SCMD_INPUT_ATK_PRIMARY));
            }
        }
Example #2
0
        /// <summary>
        /// Update is called once per frame.
        /// </summary>
        void Update()
        {
            ushort direction = Msgs.SCMD_INPUT_MOVE_STOP;
            float  horiz, vert;

            GetInputAxes(out horiz, out vert);

            // This is kind of confusing, but the input manager is translating control input directions to world directions
            // relative to the camera. Thus, if the isometric angles used by the camera change this code needs to be updated.
            // Since I don't plan to change that, this is a more efficient solution than doing quaternion math on every frame
            // to handle possible changing camera angles. Keep in mind that the world is skewed 45 degrees to the right, so on
            // an 8-direction grid, everything shifts counter-clockwise 1 place.
            if (IsDown(vert) && IsLeft(horiz))
            {
                // down+left (SW) = S
                direction = Msgs.SCMD_INPUT_MOVE_S;
            }
            else if (IsDown(vert) && IsRight(horiz))
            {
                // down+right (SE) = E
                direction = Msgs.SCMD_INPUT_MOVE_E;
            }
            else if (IsUp(vert) && IsLeft(horiz))
            {
                // up+left (NW) = W
                direction = Msgs.SCMD_INPUT_MOVE_W;
            }
            else if (IsUp(vert) && IsRight(horiz))
            {
                // up+right (NE) = N
                direction = Msgs.SCMD_INPUT_MOVE_N;
            }
            else if (IsLeft(horiz))
            {
                // left (W) = SW
                direction = Msgs.SCMD_INPUT_MOVE_SW;
            }
            else if (IsRight(horiz))
            {
                // right (E) = NE
                direction = Msgs.SCMD_INPUT_MOVE_NE;
            }
            else if (IsDown(vert))
            {
                // down (S) = SE
                direction = Msgs.SCMD_INPUT_MOVE_SE;
            }
            else if (IsUp(vert))
            {
                // up (N) = NW
                direction = Msgs.SCMD_INPUT_MOVE_NW;
            }

            // Prevent STOP spam
            if (!(direction == Msgs.SCMD_INPUT_MOVE_STOP && direction == lastDirection))
            {
                lastDirection = direction;
                // Notify other objects that the player wants to move in the specified direction
                MessageBroker.Instance.Enqueue(Msg.ClientMsg(Msgs.CMD_INPUT_MOVE, direction));
            }
        }