Ejemplo n.º 1
0
    //public static MouseInBorderRTS Create(string root, Vector3 origen, Vector3 moveTo, Transform cam)
    //{
    //    MouseInBorderRTS obj = null;
    //    obj = (MouseInBorderRTS)Resources.Load(root, typeof(MouseInBorderRTS));
    //    obj = (MouseInBorderRTS)Instantiate(obj, origen, Quaternion.identity);
    //    return obj;
    //}

    public Dir ReturnMouseDirection()
    {
        direction = Dir.None;

        //create single dir rectagles
        var recdown  = new Rect(0, 0, Screen.width, gUIsizeUpDown);
        var recup    = new Rect(0, Screen.height - gUIsizeUpDown, Screen.width, gUIsizeUpDown);
        var recleft  = new Rect(0, 0, gUIsize, Screen.height);
        var recright = new Rect(Screen.width - gUIsize, 0, gUIsize, Screen.height);

        //create composite dir rectagles
        var rectDownLeft  = new Rect(0, 0, cornerSize, cornerSize);
        var rectDownRight = new Rect(Screen.width - cornerSize, 0, cornerSize, cornerSize);
        var rectUpLeft    = new Rect(0, Screen.height - cornerSize, cornerSize, cornerSize);
        var rectUpRight   = new Rect(Screen.width - cornerSize, Screen.height - cornerSize, cornerSize, cornerSize);

        //if mouse is not on top of gui ...
        if (!MiniMapRTS.isMouseOnGUI)
        {
            direction = ReturnComposeDirection(rectDownLeft, rectDownRight,
                                               rectUpLeft, rectUpRight);

            if (direction == Dir.None)
            {
                direction = ReturnSingleDirection(recdown, recup, recleft, recright);

                if (UInput.IfCursorKeyIsPressed())
                {
                    direction = ReturnComposeDirectionWithKeyBoard(direction);
                }
            }
        }
        GlobalDir = direction;
        return(direction);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Will return in which Axis the move is happening based on Direction first
    /// pased from  MouseInBorder.cs obj, then if that is equal D.None will then
    /// look at the keyboard input
    /// </summary>
    /// <param name="horVal">horizontal axis change value </param>
    /// <param name="vertVal">vertical axis change value</param>
    /// <param name="dir">direction pased from  MouseInBorder.cs obj</param>
    /// <returns></returns>
    private Dir ReturnAxisToMove(float horVal, float vertVal, Dir dir = Dir.None)
    {
        //VerticHorizo
        //mouse
        if ((dir == Dir.UpLeft || dir == Dir.UpRight ||
             dir == Dir.DownLeft || dir == Dir.DownRight) && !IsMouseMiddle)
        {
            dir = Dir.VerticHorizo;
        }
        //keyboard
        else if ((horVal != 0 && vertVal != 0 && UInput.IfCursorKeyIsPressed()) && dir == Dir.None)
        {
            dir = Dir.VerticHorizo;
        }

        //Horizontal
        //mouse
        if (((dir == Dir.Right || dir == Dir.Left) && !IsMouseMiddle))
        {
            dir = Dir.Horizontal;
        }
        //keyobard
        else if (horVal != 0 && dir == Dir.None)
        {
            dir = Dir.Horizontal;
        }

        //Vertical
        //mouse
        if ((dir == Dir.Up || dir == Dir.Down) && !IsMouseMiddle)
        {
            dir = Dir.Vertical;
        }
        //keyobard
        else if (vertVal != 0 && dir == Dir.None)
        {
            dir = Dir.Vertical;
        }
        return(dir);
    }