Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Still trying to fix problems on the Mac side concerning DLL problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Jibran Ibrahim Syed committed Mar 8, 2017
1 parent b0dea76 commit 9abfb17
Showing 1 changed file with 59 additions and 5 deletions.
64 changes: 59 additions & 5 deletions XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using UnityEngine;
using UnityEngine.SceneManagement;

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
using XInputDotNetPure;
#endif

namespace XboxCtrlrInput
{
Expand Down Expand Up @@ -85,6 +88,7 @@ public static bool GetButton(XboxButton button)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -95,6 +99,7 @@ public static bool GetButton(XboxButton button)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -131,6 +136,7 @@ public static bool GetButton(XboxButton button, XboxController controller)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -142,6 +148,7 @@ public static bool GetButton(XboxButton button, XboxController controller)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -170,6 +177,7 @@ public static bool GetButtonDown(XboxButton button)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -183,6 +191,7 @@ public static bool GetButtonDown(XboxButton button)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -219,6 +228,7 @@ public static bool GetButtonDown(XboxButton button, XboxController controller)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -232,6 +242,7 @@ public static bool GetButtonDown(XboxButton button, XboxController controller)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -260,6 +271,7 @@ public static bool GetButtonUp(XboxButton button)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(Time.frameCount < 2)
{
return false;
Expand All @@ -278,6 +290,7 @@ public static bool GetButtonUp(XboxButton button)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -314,6 +327,7 @@ public static bool GetButtonUp(XboxButton button, XboxController controller)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(Time.frameCount < 2)
{
return false;
Expand All @@ -332,6 +346,7 @@ public static bool GetButtonUp(XboxButton button, XboxController controller)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -361,6 +376,7 @@ public static bool GetDPad(XboxDPad padDirection)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -372,6 +388,7 @@ public static bool GetDPad(XboxDPad padDirection)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -427,6 +444,7 @@ public static bool GetDPad(XboxDPad padDirection, XboxController controller)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -438,6 +456,7 @@ public static bool GetDPad(XboxDPad padDirection, XboxController controller)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -488,6 +507,7 @@ public static bool GetDPadUp(XboxDPad padDirection)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(Time.frameCount < 2)
{
return false;
Expand All @@ -506,6 +526,7 @@ public static bool GetDPadUp(XboxDPad padDirection)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -554,6 +575,7 @@ public static bool GetDPadUp(XboxDPad padDirection, XboxController controller)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(Time.frameCount < 2)
{
return false;
Expand All @@ -572,6 +594,7 @@ public static bool GetDPadUp(XboxDPad padDirection, XboxController controller)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -613,6 +636,7 @@ public static bool GetDPadDown(XboxDPad padDirection)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(Time.frameCount < 2)
{
return false;
Expand All @@ -631,6 +655,7 @@ public static bool GetDPadDown(XboxDPad padDirection)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -679,6 +704,7 @@ public static bool GetDPadDown(XboxDPad padDirection, XboxController controller)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(Time.frameCount < 2)
{
return false;
Expand All @@ -697,6 +723,7 @@ public static bool GetDPadDown(XboxDPad padDirection, XboxController controller)
{
return true;
}
#endif
}

else
Expand Down Expand Up @@ -737,6 +764,7 @@ public static float GetAxis(XboxAxis axis)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -754,6 +782,7 @@ public static float GetAxis(XboxAxis axis)
}

r = XInputApplyDeadzone(r, axis, XboxController.All);
#endif
}
else
{
Expand Down Expand Up @@ -786,6 +815,7 @@ public static float GetAxis(XboxAxis axis, XboxController controller)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -803,6 +833,7 @@ public static float GetAxis(XboxAxis axis, XboxController controller)
}

r = XInputApplyDeadzone(r, axis, controller);
#endif
}
else
{
Expand All @@ -827,6 +858,7 @@ public static float GetAxisRaw(XboxAxis axis)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -842,6 +874,7 @@ public static float GetAxisRaw(XboxAxis axis)
{
r = XInputGetAxisState(ctrlrState.ThumbSticks, axis);
}
#endif
}

else
Expand Down Expand Up @@ -875,6 +908,7 @@ public static float GetAxisRaw(XboxAxis axis, XboxController controller)

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!XInputStillInCurrFrame())
{
XInputUpdateAllStates();
Expand All @@ -890,6 +924,7 @@ public static float GetAxisRaw(XboxAxis axis, XboxController controller)
{
r = XInputGetAxisState(ctrlrState.ThumbSticks, axis);
}
#endif
}

else
Expand All @@ -914,6 +949,7 @@ public static int GetNumPluggedCtrlrs()

if(OnWindowsNative())
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(!xiNumOfCtrlrsQueried || !XInputStillInCurrFrame())
{
xiNumOfCtrlrsQueried = true;
Expand All @@ -927,6 +963,7 @@ public static int GetNumPluggedCtrlrs()
r++;
}
}
#endif
}

else
Expand Down Expand Up @@ -957,16 +994,21 @@ public static void DEBUG_LogControllerNames()
}
}





// From @xoorath
/// <summary>
/// Determines if the controller is plugged in the specified controllerNumber.
/// CAUTION: Only works on Windows Native (Desktop and Editor, not Web)!
/// CAUTION: Only works on Windows Native (Desktop and Editor)!
/// </summary>
/// <param name="controllerNumber">
/// An identifier for the specific controller on which to test the axis. An int between 1 and 4.
/// </param>
public static bool IsPluggedIn(int controllerNumber)
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
if(OnWindowsNative())
{
if (!XInputStillInCurrFrame())
Expand All @@ -978,11 +1020,12 @@ public static bool IsPluggedIn(int controllerNumber)

return ctrlrState.IsConnected;
}
#endif

// NOT IMPLEMENTED for other platforms
return false;
}




Expand All @@ -991,13 +1034,15 @@ public static bool IsPluggedIn(int controllerNumber)
////

// ------------ Members --------------- //


// Windows only subsystem
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
private static GamePadState[] xInputCtrlrs = new GamePadState[4];
private static GamePadState[] xInputCtrlrsPrev = new GamePadState[4];
private static int xiPrevFrameCount = -1;
private static bool xiUpdateAlreadyCalled = false;
private static bool xiNumOfCtrlrsQueried = false;

#endif

// ------------ Methods --------------- //

Expand Down Expand Up @@ -1533,7 +1578,8 @@ private static string DetermineDPadWirelessLinux(XboxDPad padDir, int ctrlrNum)


// ------------- Private XInput Wrappers (for Windows Native player and editor only) -------------- //


#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN

//>> For updating states <<

Expand Down Expand Up @@ -1712,6 +1758,10 @@ private static float XInputApplyDeadzone(float rawAxisValue, XboxAxis axis, Xbox

return finalValue;
}
#endif

// END of Windows only subsystem



// -------------------------- Handler Script -------------------
Expand Down Expand Up @@ -1833,5 +1883,9 @@ public static XboxDPad ToDPad(this XboxButton button)
return XboxDPad.Right;
return default(XboxDPad);
}


}


}

0 comments on commit 9abfb17

Please sign in to comment.