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

Commit 9abfb17

Browse files
author
Jibran Ibrahim Syed
committed
Still trying to fix problems on the Mac side concerning DLL problems
1 parent b0dea76 commit 9abfb17

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

XboxCtrlrInput/Assets/Plugins/XboxCtrlrInput.cs

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using UnityEngine;
22
using UnityEngine.SceneManagement;
3+
4+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
35
using XInputDotNetPure;
6+
#endif
47

58
namespace XboxCtrlrInput
69
{
@@ -85,6 +88,7 @@ public static bool GetButton(XboxButton button)
8588

8689
if(OnWindowsNative())
8790
{
91+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
8892
if(!XInputStillInCurrFrame())
8993
{
9094
XInputUpdateAllStates();
@@ -95,6 +99,7 @@ public static bool GetButton(XboxButton button)
9599
{
96100
return true;
97101
}
102+
#endif
98103
}
99104

100105
else
@@ -131,6 +136,7 @@ public static bool GetButton(XboxButton button, XboxController controller)
131136

132137
if(OnWindowsNative())
133138
{
139+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
134140
if(!XInputStillInCurrFrame())
135141
{
136142
XInputUpdateAllStates();
@@ -142,6 +148,7 @@ public static bool GetButton(XboxButton button, XboxController controller)
142148
{
143149
return true;
144150
}
151+
#endif
145152
}
146153

147154
else
@@ -170,6 +177,7 @@ public static bool GetButtonDown(XboxButton button)
170177

171178
if(OnWindowsNative())
172179
{
180+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
173181
if(!XInputStillInCurrFrame())
174182
{
175183
XInputUpdateAllStates();
@@ -183,6 +191,7 @@ public static bool GetButtonDown(XboxButton button)
183191
{
184192
return true;
185193
}
194+
#endif
186195
}
187196

188197
else
@@ -219,6 +228,7 @@ public static bool GetButtonDown(XboxButton button, XboxController controller)
219228

220229
if(OnWindowsNative())
221230
{
231+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
222232
if(!XInputStillInCurrFrame())
223233
{
224234
XInputUpdateAllStates();
@@ -232,6 +242,7 @@ public static bool GetButtonDown(XboxButton button, XboxController controller)
232242
{
233243
return true;
234244
}
245+
#endif
235246
}
236247

237248
else
@@ -260,6 +271,7 @@ public static bool GetButtonUp(XboxButton button)
260271

261272
if(OnWindowsNative())
262273
{
274+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
263275
if(Time.frameCount < 2)
264276
{
265277
return false;
@@ -278,6 +290,7 @@ public static bool GetButtonUp(XboxButton button)
278290
{
279291
return true;
280292
}
293+
#endif
281294
}
282295

283296
else
@@ -314,6 +327,7 @@ public static bool GetButtonUp(XboxButton button, XboxController controller)
314327

315328
if(OnWindowsNative())
316329
{
330+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
317331
if(Time.frameCount < 2)
318332
{
319333
return false;
@@ -332,6 +346,7 @@ public static bool GetButtonUp(XboxButton button, XboxController controller)
332346
{
333347
return true;
334348
}
349+
#endif
335350
}
336351

337352
else
@@ -361,6 +376,7 @@ public static bool GetDPad(XboxDPad padDirection)
361376

362377
if(OnWindowsNative())
363378
{
379+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
364380
if(!XInputStillInCurrFrame())
365381
{
366382
XInputUpdateAllStates();
@@ -372,6 +388,7 @@ public static bool GetDPad(XboxDPad padDirection)
372388
{
373389
return true;
374390
}
391+
#endif
375392
}
376393

377394
else
@@ -427,6 +444,7 @@ public static bool GetDPad(XboxDPad padDirection, XboxController controller)
427444

428445
if(OnWindowsNative())
429446
{
447+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
430448
if(!XInputStillInCurrFrame())
431449
{
432450
XInputUpdateAllStates();
@@ -438,6 +456,7 @@ public static bool GetDPad(XboxDPad padDirection, XboxController controller)
438456
{
439457
return true;
440458
}
459+
#endif
441460
}
442461

443462
else
@@ -488,6 +507,7 @@ public static bool GetDPadUp(XboxDPad padDirection)
488507

489508
if(OnWindowsNative())
490509
{
510+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
491511
if(Time.frameCount < 2)
492512
{
493513
return false;
@@ -506,6 +526,7 @@ public static bool GetDPadUp(XboxDPad padDirection)
506526
{
507527
return true;
508528
}
529+
#endif
509530
}
510531

511532
else
@@ -554,6 +575,7 @@ public static bool GetDPadUp(XboxDPad padDirection, XboxController controller)
554575

555576
if(OnWindowsNative())
556577
{
578+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
557579
if(Time.frameCount < 2)
558580
{
559581
return false;
@@ -572,6 +594,7 @@ public static bool GetDPadUp(XboxDPad padDirection, XboxController controller)
572594
{
573595
return true;
574596
}
597+
#endif
575598
}
576599

577600
else
@@ -613,6 +636,7 @@ public static bool GetDPadDown(XboxDPad padDirection)
613636

614637
if(OnWindowsNative())
615638
{
639+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
616640
if(Time.frameCount < 2)
617641
{
618642
return false;
@@ -631,6 +655,7 @@ public static bool GetDPadDown(XboxDPad padDirection)
631655
{
632656
return true;
633657
}
658+
#endif
634659
}
635660

636661
else
@@ -679,6 +704,7 @@ public static bool GetDPadDown(XboxDPad padDirection, XboxController controller)
679704

680705
if(OnWindowsNative())
681706
{
707+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
682708
if(Time.frameCount < 2)
683709
{
684710
return false;
@@ -697,6 +723,7 @@ public static bool GetDPadDown(XboxDPad padDirection, XboxController controller)
697723
{
698724
return true;
699725
}
726+
#endif
700727
}
701728

702729
else
@@ -737,6 +764,7 @@ public static float GetAxis(XboxAxis axis)
737764

738765
if(OnWindowsNative())
739766
{
767+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
740768
if(!XInputStillInCurrFrame())
741769
{
742770
XInputUpdateAllStates();
@@ -754,6 +782,7 @@ public static float GetAxis(XboxAxis axis)
754782
}
755783

756784
r = XInputApplyDeadzone(r, axis, XboxController.All);
785+
#endif
757786
}
758787
else
759788
{
@@ -786,6 +815,7 @@ public static float GetAxis(XboxAxis axis, XboxController controller)
786815

787816
if(OnWindowsNative())
788817
{
818+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
789819
if(!XInputStillInCurrFrame())
790820
{
791821
XInputUpdateAllStates();
@@ -803,6 +833,7 @@ public static float GetAxis(XboxAxis axis, XboxController controller)
803833
}
804834

805835
r = XInputApplyDeadzone(r, axis, controller);
836+
#endif
806837
}
807838
else
808839
{
@@ -827,6 +858,7 @@ public static float GetAxisRaw(XboxAxis axis)
827858

828859
if(OnWindowsNative())
829860
{
861+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
830862
if(!XInputStillInCurrFrame())
831863
{
832864
XInputUpdateAllStates();
@@ -842,6 +874,7 @@ public static float GetAxisRaw(XboxAxis axis)
842874
{
843875
r = XInputGetAxisState(ctrlrState.ThumbSticks, axis);
844876
}
877+
#endif
845878
}
846879

847880
else
@@ -875,6 +908,7 @@ public static float GetAxisRaw(XboxAxis axis, XboxController controller)
875908

876909
if(OnWindowsNative())
877910
{
911+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
878912
if(!XInputStillInCurrFrame())
879913
{
880914
XInputUpdateAllStates();
@@ -890,6 +924,7 @@ public static float GetAxisRaw(XboxAxis axis, XboxController controller)
890924
{
891925
r = XInputGetAxisState(ctrlrState.ThumbSticks, axis);
892926
}
927+
#endif
893928
}
894929

895930
else
@@ -914,6 +949,7 @@ public static int GetNumPluggedCtrlrs()
914949

915950
if(OnWindowsNative())
916951
{
952+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
917953
if(!xiNumOfCtrlrsQueried || !XInputStillInCurrFrame())
918954
{
919955
xiNumOfCtrlrsQueried = true;
@@ -927,6 +963,7 @@ public static int GetNumPluggedCtrlrs()
927963
r++;
928964
}
929965
}
966+
#endif
930967
}
931968

932969
else
@@ -957,16 +994,21 @@ public static void DEBUG_LogControllerNames()
957994
}
958995
}
959996

997+
998+
999+
1000+
9601001
// From @xoorath
9611002
/// <summary>
9621003
/// Determines if the controller is plugged in the specified controllerNumber.
963-
/// CAUTION: Only works on Windows Native (Desktop and Editor, not Web)!
1004+
/// CAUTION: Only works on Windows Native (Desktop and Editor)!
9641005
/// </summary>
9651006
/// <param name="controllerNumber">
9661007
/// An identifier for the specific controller on which to test the axis. An int between 1 and 4.
9671008
/// </param>
9681009
public static bool IsPluggedIn(int controllerNumber)
9691010
{
1011+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
9701012
if(OnWindowsNative())
9711013
{
9721014
if (!XInputStillInCurrFrame())
@@ -978,11 +1020,12 @@ public static bool IsPluggedIn(int controllerNumber)
9781020

9791021
return ctrlrState.IsConnected;
9801022
}
1023+
#endif
9811024

9821025
// NOT IMPLEMENTED for other platforms
9831026
return false;
9841027
}
985-
1028+
9861029

9871030

9881031

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

9931036
// ------------ Members --------------- //
994-
1037+
1038+
// Windows only subsystem
1039+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
9951040
private static GamePadState[] xInputCtrlrs = new GamePadState[4];
9961041
private static GamePadState[] xInputCtrlrsPrev = new GamePadState[4];
9971042
private static int xiPrevFrameCount = -1;
9981043
private static bool xiUpdateAlreadyCalled = false;
9991044
private static bool xiNumOfCtrlrsQueried = false;
1000-
1045+
#endif
10011046

10021047
// ------------ Methods --------------- //
10031048

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

15341579

15351580
// ------------- Private XInput Wrappers (for Windows Native player and editor only) -------------- //
1536-
1581+
1582+
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
15371583

15381584
//>> For updating states <<
15391585

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

17131759
return finalValue;
17141760
}
1761+
#endif
1762+
1763+
// END of Windows only subsystem
1764+
17151765

17161766

17171767
// -------------------------- Handler Script -------------------
@@ -1833,5 +1883,9 @@ public static XboxDPad ToDPad(this XboxButton button)
18331883
return XboxDPad.Right;
18341884
return default(XboxDPad);
18351885
}
1886+
1887+
18361888
}
1889+
1890+
18371891
}

0 commit comments

Comments
 (0)