Ejemplo n.º 1
0
    /// <summary>
    /// Will decompose a Compose Direction (ex: UpRight), into Up and Right so the
    /// mouse direction will be valid if is in a corner, if is a simpel direction
    /// will be send in the first item of the 'List<D> localDirs' , 2nd item will be D.none.
    /// If composeDir == D.none , both items in the list will be equal to so.
    /// </summary>
    /// <param name="composeDir">direction that MouseInBorder.cs obj is sending</param>
    /// <returns></returns>
    private List <float> DecomposeDirectionRetValues(Dir composeDir)
    {
        List <Dir> localDirs = new List <Dir>();

        if (composeDir == Dir.DownRight)
        {
            //when decomposing always X axis 1st and then Y axis
            localDirs.Add(Dir.Right);
            localDirs.Add(Dir.Down);
        }
        else if (composeDir == Dir.DownLeft)
        {
            localDirs.Add(Dir.Left);
            localDirs.Add(Dir.Down);
        }
        else if (composeDir == Dir.UpRight)
        {
            localDirs.Add(Dir.Right);
            localDirs.Add(Dir.Up);
        }
        else if (composeDir == Dir.UpLeft)
        {
            localDirs.Add(Dir.Left);
            localDirs.Add(Dir.Up);
        }
        //when is not really a composed direction
        else
        {
            //will assign both values to current direction in the below
            // ResponsiveInputAxisTo() will descriminate given the axis
            localDirs.Add(composeDir);
            localDirs.Add(composeDir);
        }

        float horChange  = 0;
        float vertChange = 0;

        //if localDirections are none user is not moving the camera with mouse
        //therefore can use the keyboad to move
        if (localDirs[0] == Dir.None)
        {
            horChange  = Input.GetAxis("Horizontal");
            vertChange = Input.GetAxis("Vertical");
        }
        //if user is using mouse horChange and vertChange will remaing at 0 therefore
        //subsequente method will find where to go based on mouse direction

        float horValue = UMath.ResponsiveInputAxisTo(_desiredSpeed, Dir.Horizontal,
                                                     horChange, localDirs[0]);
        float vertValue = UMath.ResponsiveInputAxisTo(_desiredSpeed, Dir.Vertical,
                                                      vertChange, localDirs[1]);

        return(new List <float> {
            horValue, vertValue
        });
    }