/// <summary> Returns <c>true</c> if the specified D-Pad direction is pressed down by a specified controller. </summary>
        /// <param name='padDirection'> An identifier for the specified D-Pad direction to be tested. </param>
        /// <param name='controllerNumber'> An identifier for the specific controller on which to test the D-Pad. </param>
        public static bool GetDPad(XboxDPad padDirection, int controllerNumber)
        {
            bool   r         = false;
            string inputCode = "";

            if (OnMac())
            {
                inputCode = DetermineDPadMac(padDirection, controllerNumber);
                r         = Input.GetKey(inputCode);
            }
            else
            {
                inputCode = DetermineDPad(padDirection, controllerNumber);

                switch (padDirection)
                {
                case XboxDPad.Up:               r = Input.GetAxis(inputCode) > 0; break;

                case XboxDPad.Down:     r = Input.GetAxis(inputCode) < 0; break;

                case XboxDPad.Left:     r = Input.GetAxis(inputCode) < 0; break;

                case XboxDPad.Right:    r = Input.GetAxis(inputCode) > 0; break;

                default: r = false; break;
                }
            }

            return(r);
        }
        /// <summary> Returns <c>true</c> if the specified D-Pad direction is pressed down by a specified controller. </summary>
        /// <param name='padDirection'> An identifier for the specified D-Pad direction to be tested. </param>
        /// <param name='controllerNumber'> An identifier for the specific controller on which to test the D-Pad. An int between 1 and 4. </param>
        public static bool GetDPad(XboxDPad padDirection, int controllerNumber)
        {
            bool r = false;

            if (OnWindowsNative())
            {
                if (!XInputStillInCurrFrame())
                {
                    XInputUpdateAllStates();                     //XInputUpdatePaticularState(controllerNumber);
                }

                GamePadState ctrlrState = XInputGetPaticularState(controllerNumber);

                if (XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed)
                {
                    return(true);
                }
            }

            else
            {
                string inputCode = "";

                if (OnMac())
                {
                    inputCode = DetermineDPadMac(padDirection, controllerNumber);
                    r         = Input.GetKey(inputCode);
                }
                else if (OnLinux() && IsControllerWireless(controllerNumber))
                {
                    inputCode = DetermineDPadWirelessLinux(padDirection, controllerNumber);
                    r         = Input.GetKey(inputCode);
                }
                else
                {
                    inputCode = DetermineDPad(padDirection, controllerNumber);

                    switch (padDirection)
                    {
                    case XboxDPad.Up:               r = Input.GetAxis(inputCode) > 0; break;

                    case XboxDPad.Down:     r = Input.GetAxis(inputCode) < 0; break;

                    case XboxDPad.Left:     r = Input.GetAxis(inputCode) < 0; break;

                    case XboxDPad.Right:    r = Input.GetAxis(inputCode) > 0; break;

                    default: r = false; break;
                    }
                }
            }

            return(r);
        }
        /// <summary> Returns <c>true</c> at the frame the specified button is Pressed by a specified controller. </summary>
        /// <param name='button'> Identifier for the Xbox button to be tested. </param>
        /// <param name='controllerNumber'> An identifier for the specific controller on which to test the button. An int between 1 and 4. </param>
        public static bool GetDPadDown(XboxDPad padDirection, int controllerNumber)
        {
            bool r = false;

            if (OnWindowsNative())
            {
                if (Time.frameCount < 2)
                {
                    return(false);
                }

                if (!XInputStillInCurrFrame())
                {
                    XInputUpdateAllStates();                     //XInputUpdatePaticularState(controllerNumber);
                }

                GamePadState ctrlrState     = XInputGetPaticularState(controllerNumber);
                GamePadState ctrlrStatePrev = XInputGetPaticularStatePrev(controllerNumber);

                if ((XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed) &&
                    (XInputGetDPadState(ctrlrStatePrev.DPad, padDirection) == ButtonState.Released))
                {
                    return(true);
                }
            }

            else
            {
                string inputCode = "";

                if (OnMac())
                {
                    inputCode = DetermineDPadMac(padDirection, controllerNumber);
                    r         = Input.GetKeyDown(inputCode);
                }
                else if (OnLinux() && IsControllerWireless(controllerNumber))
                {
                    inputCode = DetermineDPadWirelessLinux(padDirection, controllerNumber);
                    r         = Input.GetKeyDown(inputCode);
                }
                else
                {
                    //Place Holder for Wired Linux
                    r = false;
                }
            }

            return(r);
        }
        private static string DetermineDPad(XboxDPad padDir, int ctrlrNum)
        {
            string r           = "";
            string sJoyCode    = ctrlrNum.ToString();
            string sPadCode    = "";
            bool   invalidCode = false;

            if (OnLinux())
            {
                switch (padDir)
                {
                case XboxDPad.Up:               sPadCode = "8"; break;

                case XboxDPad.Down:             sPadCode = "8"; break;

                case XboxDPad.Left:             sPadCode = "7"; break;

                case XboxDPad.Right:    sPadCode = "7"; break;

                default: invalidCode = true; break;
                }
            }
            else
            {
                switch (padDir)
                {
                case XboxDPad.Up:               sPadCode = "7"; break;

                case XboxDPad.Down:             sPadCode = "7"; break;

                case XboxDPad.Left:             sPadCode = "6"; break;

                case XboxDPad.Right:    sPadCode = "6"; break;

                default: invalidCode = true; break;
                }
            }

            r = "XboxAxis" + sPadCode + "Joy" + sJoyCode;

            if (invalidCode)
            {
                r = "";
            }

            return(r);
        }
        private static ButtonState XInputGetDPadState(GamePadDPad xiDPad, XboxDPad xciDPad)
        {
            ButtonState stateToReturn = ButtonState.Released;

            switch (xciDPad)
            {
            case XboxDPad.Up:                               stateToReturn = xiDPad.Up; break;

            case XboxDPad.Down:                     stateToReturn = xiDPad.Down; break;

            case XboxDPad.Left:                     stateToReturn = xiDPad.Left; break;

            case XboxDPad.Right:                    stateToReturn = xiDPad.Right; break;
            }

            return(stateToReturn);
        }
        private static string DetermineDPadWirelessLinux(XboxDPad padDir, int ctrlrNum)
        {
            string r           = "";
            string sJoyCode    = "";
            string sPadCode    = "";
            bool   invalidCode = false;

            if (ctrlrNum == 0)
            {
                sJoyCode = "";
            }
            else
            {
                sJoyCode = " " + ctrlrNum.ToString();
            }

            switch (padDir)
            {
            case XboxDPad.Up:               sPadCode = "13"; break;

            case XboxDPad.Down:             sPadCode = "14"; break;

            case XboxDPad.Left:             sPadCode = "11"; break;

            case XboxDPad.Right:    sPadCode = "12"; break;

            default: invalidCode = true; break;
            }

            r = "joystick" + sJoyCode + " button " + sPadCode;

            if (invalidCode)
            {
                r = "";
            }

            return(r);
        }
        private static string DetermineDPadMac(XboxDPad padDir, int ctrlrNum)
        {
            string r = "";
            string sJoyCode = "";
            string sPadCode = "";
            bool invalidCode = false;

            if(ctrlrNum == 0)
            {
                sJoyCode = "";
            }
            else
            {
                sJoyCode = " " + ctrlrNum.ToString();
            }

            switch(padDir)
            {
                case XboxDPad.Up: 		sPadCode = "5"; break;
                case XboxDPad.Down:		sPadCode = "6"; break;
                case XboxDPad.Left:		sPadCode = "7"; break;
                case XboxDPad.Right:	sPadCode = "8"; break;

                default: invalidCode = true; break;
            }

            r = "joystick" + sJoyCode + " button " + sPadCode;

            if(invalidCode)
            {
                r = "";
            }

            return r;
        }
        private static string DetermineDPad(XboxDPad padDir, int ctrlrNum)
        {
            string r = "";
            string sJoyCode = ctrlrNum.ToString();
            string sPadCode = "";
            bool invalidCode = false;

            if(OnLinux())
            {
                switch(padDir)
                {
                    case XboxDPad.Up: 		sPadCode = "8"; break;
                    case XboxDPad.Down:		sPadCode = "8"; break;
                    case XboxDPad.Left:		sPadCode = "7"; break;
                    case XboxDPad.Right:	sPadCode = "7"; break;

                    default: invalidCode = true; break;
                }
            }
            else
            {
                switch(padDir)
                {
                    case XboxDPad.Up: 		sPadCode = "7"; break;
                    case XboxDPad.Down:		sPadCode = "7"; break;
                    case XboxDPad.Left:		sPadCode = "6"; break;
                    case XboxDPad.Right:	sPadCode = "6"; break;

                    default: invalidCode = true; break;
                }
            }

            r = "XboxAxis" + sPadCode + "Joy" + sJoyCode;

            if(invalidCode)
            {
                r = "";
            }

            return r;
        }
        /// <summary> Returns <c>true</c> if the specified D-Pad direction is pressed down by a specified controller. </summary>
        /// <param name='padDirection'> An identifier for the specified D-Pad direction to be tested. </param>
        /// <param name='controllerNumber'> An identifier for the specific controller on which to test the D-Pad. </param>
        public static bool GetDPad(XboxDPad padDirection, int controllerNumber)
        {
            bool r = false;
            string inputCode = "";

            if(OnMac())
            {
                inputCode = DetermineDPadMac(padDirection, controllerNumber);
                r = Input.GetKey(inputCode);
            }
            else
            {
                inputCode = DetermineDPad(padDirection, controllerNumber);

                switch(padDirection)
                {
                    case XboxDPad.Up: 		r = Input.GetAxis(inputCode) > 0; break;
                    case XboxDPad.Down: 	r = Input.GetAxis(inputCode) < 0; break;
                    case XboxDPad.Left: 	r = Input.GetAxis(inputCode) < 0; break;
                    case XboxDPad.Right:	r = Input.GetAxis(inputCode) > 0; break;

                    default: r = false; break;
                }
            }

            return r;
        }
		// From @ProjectEnder
		/// <summary> 
		/// 	Returns <c>true</c> at the frame the specified button is Pressed by a specified controller. 
		/// 	Does NOT work on Linux with Wired Controllers.
		/// </summary>
		/// <param name='button'> 
		/// 	Identifier for the Xbox button to be tested. 
		/// </param>
		/// <param name='controller'>
		/// 	An identifier for the specific controller on which to test the button.
		/// </param>
		public static bool GetDPadDown(XboxDPad padDirection, XboxController controller)
		{
			if (controller == XboxController.All)
				return GetDPadDown(padDirection);

			int controllerNumber = (int)controller;

			bool r = false;
			
			if(OnWindowsNative())
			{
				if(Time.frameCount < 2)
				{
					return false;
				}
				
				if(!XInputStillInCurrFrame())
				{
					XInputUpdateAllStates();
				}
				
				GamePadState ctrlrState = XInputGetPaticularState(controllerNumber);
				GamePadState ctrlrStatePrev = XInputGetPaticularStatePrev(controllerNumber);
				
				if( ( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed ) &&
				   ( XInputGetDPadState(ctrlrStatePrev.DPad, padDirection) == ButtonState.Released ) )
				{
					return true;
				}
			}
			
			else
			{
				string inputCode = "";
				
				if(OnMac())
				{
					inputCode = DetermineDPadMac(padDirection, controllerNumber);
					r = Input.GetKeyDown(inputCode);
				}
				else if(OnLinux() && IsControllerWireless(controllerNumber))
				{
					inputCode = DetermineDPadWirelessLinux(padDirection, controllerNumber);
					r = Input.GetKeyDown(inputCode);
				}
				else
				{
					//Place Holder for Wired Linux
					r = false;
				}
			}
			
			return r;
		}
		// From @ProjectEnder
		/// <summary> 
		/// 	Returns <c>true</c> at the frame the specified button is released.
		/// 	Does NOT work on Linux with Wired Controllers.
		/// </summary>
		/// <param name='button'> 
		/// 	Identifier for the Xbox button to be tested. 
		/// </param>
		public static bool GetDPadUp(XboxDPad padDirection)
		{
			
			bool r = false;
			
			if(OnWindowsNative())
			{
				if(Time.frameCount < 2)
				{
					return false;
				}
				
				if(!XInputStillInCurrFrame())
				{
					XInputUpdateAllStates();
				}
				
				GamePadState ctrlrState = XInputGetSingleState();
				GamePadState ctrlrStatePrev = XInputGetSingleStatePrev();
				
				if( ( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Released ) &&
				   ( XInputGetDPadState(ctrlrStatePrev.DPad, padDirection) == ButtonState.Pressed ) )
				{
					return true;
				}
			}
			
			else
			{
				string inputCode = "";
				
				if(OnMac())
				{
					inputCode = DetermineDPadMac(padDirection, 0);
					r = Input.GetKeyUp(inputCode);
				}
				else if(OnLinux() && IsControllerWireless())
				{
					inputCode = DetermineDPadWirelessLinux(padDirection, 0);
					r = Input.GetKeyUp(inputCode);
				}
				else
				{
					//Place Holder for Wired Linux
					r = false;
				}					
			}
			
			return r;
		}
		/// <summary> 
		/// 	Returns <c>true</c> if the specified D-Pad direction is pressed down by a specified controller. 
		/// </summary>
		/// <param name='padDirection'> 
		/// 	An identifier for the specified D-Pad direction to be tested. 
		/// </param>
		/// <param name='controller'>
		/// 	An identifier for the specific controller on which to test the D-Pad.
		/// </param>
		public static bool GetDPad(XboxDPad padDirection, XboxController controller)
		{
			if (controller == XboxController.All)
				return GetDPad(padDirection);

			int controllerNumber = (int)controller;

			bool r = false;
			
			if(OnWindowsNative())
			{
				if(!XInputStillInCurrFrame())
				{
					XInputUpdateAllStates();
				}
				
				GamePadState ctrlrState = XInputGetPaticularState(controllerNumber);

				if( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed )
				{
					return true;
				}
			}
			
			else
			{
				string inputCode = "";
				
				if(OnMac())
				{
					inputCode = DetermineDPadMac(padDirection, controllerNumber);
					r = Input.GetKey(inputCode);
				}
				else if(OnLinux() && IsControllerWireless(controllerNumber))
				{
					inputCode = DetermineDPadWirelessLinux(padDirection, controllerNumber);
					r = Input.GetKey(inputCode);
				}
				else // Windows Web Player and Linux Wired Controller
				{
					inputCode = DetermineDPad(padDirection, controllerNumber);
					
					switch(padDirection)
					{
						case XboxDPad.Up: 		r = Input.GetAxis(inputCode) > 0; break;
						case XboxDPad.Down: 	r = Input.GetAxis(inputCode) < 0; break;
						case XboxDPad.Left: 	r = Input.GetAxis(inputCode) < 0; break;
						case XboxDPad.Right:	r = Input.GetAxis(inputCode) > 0; break;
						
						default: r = false; break;
					}
				}
			}
			
			return r;
		}
		private static ButtonState XInputGetDPadState(GamePadDPad xiDPad, XboxDPad xciDPad)
		{
			ButtonState stateToReturn = ButtonState.Released;
			
			switch(xciDPad)
			{
				case XboxDPad.Up: 				stateToReturn = xiDPad.Up; break;
				case XboxDPad.Down: 			stateToReturn = xiDPad.Down; break;
				case XboxDPad.Left: 			stateToReturn = xiDPad.Left; break;
				case XboxDPad.Right: 			stateToReturn = xiDPad.Right; break;
			}
			
			return stateToReturn;
		}
		// >>> For D-Pad <<< //
		
		/// <summary> Returns <c>true</c> if the specified D-Pad direction is pressed down by any controller. </summary>
		/// <param name='padDirection'> An identifier for the specified D-Pad direction to be tested. </param>
		public static bool GetDPad(XboxDPad padDirection)
		{
			bool r = false;
			
			if(OnWindowsNative())
			{
				if(!XInputStillInCurrFrame())
				{
					XInputUpdateAllStates(); //XInputUpdateSingleState();
				}
				
				GamePadState ctrlrState = XInputGetSingleState();
				
				if( XInputGetDPadState(ctrlrState.DPad, padDirection) == ButtonState.Pressed )
				{
					return true;
				}
			}
			
			else
			{				
				string inputCode = "";
				
				if(OnMac())
				{
					inputCode = DetermineDPadMac(padDirection, 0);
					r = Input.GetKey(inputCode);
				}
				else if(OnLinux() && IsControllerWireless())
				{
					inputCode = DetermineDPadWirelessLinux(padDirection, 0);
					r = Input.GetKey(inputCode);
				}
				else
				{
					inputCode = DetermineDPad(padDirection, 0);
					
					switch(padDirection)
					{
						case XboxDPad.Up: 		r = Input.GetAxis(inputCode) > 0; break;
						case XboxDPad.Down: 	r = Input.GetAxis(inputCode) < 0; break;
						case XboxDPad.Left: 	r = Input.GetAxis(inputCode) < 0; break;
						case XboxDPad.Right:	r = Input.GetAxis(inputCode) > 0; break;
						
						default: r = false; break;
					}
				}
			}
				
			return r;
		}