1
1
using UnityEngine ;
2
2
using UnityEngine . SceneManagement ;
3
+
4
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
3
5
using XInputDotNetPure ;
6
+ #endif
4
7
5
8
namespace XboxCtrlrInput
6
9
{
@@ -85,6 +88,7 @@ public static bool GetButton(XboxButton button)
85
88
86
89
if ( OnWindowsNative ( ) )
87
90
{
91
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
88
92
if ( ! XInputStillInCurrFrame ( ) )
89
93
{
90
94
XInputUpdateAllStates ( ) ;
@@ -95,6 +99,7 @@ public static bool GetButton(XboxButton button)
95
99
{
96
100
return true ;
97
101
}
102
+ #endif
98
103
}
99
104
100
105
else
@@ -131,6 +136,7 @@ public static bool GetButton(XboxButton button, XboxController controller)
131
136
132
137
if ( OnWindowsNative ( ) )
133
138
{
139
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
134
140
if ( ! XInputStillInCurrFrame ( ) )
135
141
{
136
142
XInputUpdateAllStates ( ) ;
@@ -142,6 +148,7 @@ public static bool GetButton(XboxButton button, XboxController controller)
142
148
{
143
149
return true ;
144
150
}
151
+ #endif
145
152
}
146
153
147
154
else
@@ -170,6 +177,7 @@ public static bool GetButtonDown(XboxButton button)
170
177
171
178
if ( OnWindowsNative ( ) )
172
179
{
180
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
173
181
if ( ! XInputStillInCurrFrame ( ) )
174
182
{
175
183
XInputUpdateAllStates ( ) ;
@@ -183,6 +191,7 @@ public static bool GetButtonDown(XboxButton button)
183
191
{
184
192
return true ;
185
193
}
194
+ #endif
186
195
}
187
196
188
197
else
@@ -219,6 +228,7 @@ public static bool GetButtonDown(XboxButton button, XboxController controller)
219
228
220
229
if ( OnWindowsNative ( ) )
221
230
{
231
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
222
232
if ( ! XInputStillInCurrFrame ( ) )
223
233
{
224
234
XInputUpdateAllStates ( ) ;
@@ -232,6 +242,7 @@ public static bool GetButtonDown(XboxButton button, XboxController controller)
232
242
{
233
243
return true ;
234
244
}
245
+ #endif
235
246
}
236
247
237
248
else
@@ -260,6 +271,7 @@ public static bool GetButtonUp(XboxButton button)
260
271
261
272
if ( OnWindowsNative ( ) )
262
273
{
274
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
263
275
if ( Time . frameCount < 2 )
264
276
{
265
277
return false ;
@@ -278,6 +290,7 @@ public static bool GetButtonUp(XboxButton button)
278
290
{
279
291
return true ;
280
292
}
293
+ #endif
281
294
}
282
295
283
296
else
@@ -314,6 +327,7 @@ public static bool GetButtonUp(XboxButton button, XboxController controller)
314
327
315
328
if ( OnWindowsNative ( ) )
316
329
{
330
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
317
331
if ( Time . frameCount < 2 )
318
332
{
319
333
return false ;
@@ -332,6 +346,7 @@ public static bool GetButtonUp(XboxButton button, XboxController controller)
332
346
{
333
347
return true ;
334
348
}
349
+ #endif
335
350
}
336
351
337
352
else
@@ -361,6 +376,7 @@ public static bool GetDPad(XboxDPad padDirection)
361
376
362
377
if ( OnWindowsNative ( ) )
363
378
{
379
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
364
380
if ( ! XInputStillInCurrFrame ( ) )
365
381
{
366
382
XInputUpdateAllStates ( ) ;
@@ -372,6 +388,7 @@ public static bool GetDPad(XboxDPad padDirection)
372
388
{
373
389
return true ;
374
390
}
391
+ #endif
375
392
}
376
393
377
394
else
@@ -427,6 +444,7 @@ public static bool GetDPad(XboxDPad padDirection, XboxController controller)
427
444
428
445
if ( OnWindowsNative ( ) )
429
446
{
447
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
430
448
if ( ! XInputStillInCurrFrame ( ) )
431
449
{
432
450
XInputUpdateAllStates ( ) ;
@@ -438,6 +456,7 @@ public static bool GetDPad(XboxDPad padDirection, XboxController controller)
438
456
{
439
457
return true ;
440
458
}
459
+ #endif
441
460
}
442
461
443
462
else
@@ -488,6 +507,7 @@ public static bool GetDPadUp(XboxDPad padDirection)
488
507
489
508
if ( OnWindowsNative ( ) )
490
509
{
510
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
491
511
if ( Time . frameCount < 2 )
492
512
{
493
513
return false ;
@@ -506,6 +526,7 @@ public static bool GetDPadUp(XboxDPad padDirection)
506
526
{
507
527
return true ;
508
528
}
529
+ #endif
509
530
}
510
531
511
532
else
@@ -554,6 +575,7 @@ public static bool GetDPadUp(XboxDPad padDirection, XboxController controller)
554
575
555
576
if ( OnWindowsNative ( ) )
556
577
{
578
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
557
579
if ( Time . frameCount < 2 )
558
580
{
559
581
return false ;
@@ -572,6 +594,7 @@ public static bool GetDPadUp(XboxDPad padDirection, XboxController controller)
572
594
{
573
595
return true ;
574
596
}
597
+ #endif
575
598
}
576
599
577
600
else
@@ -613,6 +636,7 @@ public static bool GetDPadDown(XboxDPad padDirection)
613
636
614
637
if ( OnWindowsNative ( ) )
615
638
{
639
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
616
640
if ( Time . frameCount < 2 )
617
641
{
618
642
return false ;
@@ -631,6 +655,7 @@ public static bool GetDPadDown(XboxDPad padDirection)
631
655
{
632
656
return true ;
633
657
}
658
+ #endif
634
659
}
635
660
636
661
else
@@ -679,6 +704,7 @@ public static bool GetDPadDown(XboxDPad padDirection, XboxController controller)
679
704
680
705
if ( OnWindowsNative ( ) )
681
706
{
707
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
682
708
if ( Time . frameCount < 2 )
683
709
{
684
710
return false ;
@@ -697,6 +723,7 @@ public static bool GetDPadDown(XboxDPad padDirection, XboxController controller)
697
723
{
698
724
return true ;
699
725
}
726
+ #endif
700
727
}
701
728
702
729
else
@@ -737,6 +764,7 @@ public static float GetAxis(XboxAxis axis)
737
764
738
765
if ( OnWindowsNative ( ) )
739
766
{
767
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
740
768
if ( ! XInputStillInCurrFrame ( ) )
741
769
{
742
770
XInputUpdateAllStates ( ) ;
@@ -754,6 +782,7 @@ public static float GetAxis(XboxAxis axis)
754
782
}
755
783
756
784
r = XInputApplyDeadzone ( r , axis , XboxController . All ) ;
785
+ #endif
757
786
}
758
787
else
759
788
{
@@ -786,6 +815,7 @@ public static float GetAxis(XboxAxis axis, XboxController controller)
786
815
787
816
if ( OnWindowsNative ( ) )
788
817
{
818
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
789
819
if ( ! XInputStillInCurrFrame ( ) )
790
820
{
791
821
XInputUpdateAllStates ( ) ;
@@ -803,6 +833,7 @@ public static float GetAxis(XboxAxis axis, XboxController controller)
803
833
}
804
834
805
835
r = XInputApplyDeadzone ( r , axis , controller ) ;
836
+ #endif
806
837
}
807
838
else
808
839
{
@@ -827,6 +858,7 @@ public static float GetAxisRaw(XboxAxis axis)
827
858
828
859
if ( OnWindowsNative ( ) )
829
860
{
861
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
830
862
if ( ! XInputStillInCurrFrame ( ) )
831
863
{
832
864
XInputUpdateAllStates ( ) ;
@@ -842,6 +874,7 @@ public static float GetAxisRaw(XboxAxis axis)
842
874
{
843
875
r = XInputGetAxisState ( ctrlrState . ThumbSticks , axis ) ;
844
876
}
877
+ #endif
845
878
}
846
879
847
880
else
@@ -875,6 +908,7 @@ public static float GetAxisRaw(XboxAxis axis, XboxController controller)
875
908
876
909
if ( OnWindowsNative ( ) )
877
910
{
911
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
878
912
if ( ! XInputStillInCurrFrame ( ) )
879
913
{
880
914
XInputUpdateAllStates ( ) ;
@@ -890,6 +924,7 @@ public static float GetAxisRaw(XboxAxis axis, XboxController controller)
890
924
{
891
925
r = XInputGetAxisState ( ctrlrState . ThumbSticks , axis ) ;
892
926
}
927
+ #endif
893
928
}
894
929
895
930
else
@@ -914,6 +949,7 @@ public static int GetNumPluggedCtrlrs()
914
949
915
950
if ( OnWindowsNative ( ) )
916
951
{
952
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
917
953
if ( ! xiNumOfCtrlrsQueried || ! XInputStillInCurrFrame ( ) )
918
954
{
919
955
xiNumOfCtrlrsQueried = true ;
@@ -927,6 +963,7 @@ public static int GetNumPluggedCtrlrs()
927
963
r ++ ;
928
964
}
929
965
}
966
+ #endif
930
967
}
931
968
932
969
else
@@ -957,16 +994,21 @@ public static void DEBUG_LogControllerNames()
957
994
}
958
995
}
959
996
997
+
998
+
999
+
1000
+
960
1001
// From @xoorath
961
1002
/// <summary>
962
1003
/// 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)!
964
1005
/// </summary>
965
1006
/// <param name="controllerNumber">
966
1007
/// An identifier for the specific controller on which to test the axis. An int between 1 and 4.
967
1008
/// </param>
968
1009
public static bool IsPluggedIn ( int controllerNumber )
969
1010
{
1011
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
970
1012
if ( OnWindowsNative ( ) )
971
1013
{
972
1014
if ( ! XInputStillInCurrFrame ( ) )
@@ -978,11 +1020,12 @@ public static bool IsPluggedIn(int controllerNumber)
978
1020
979
1021
return ctrlrState . IsConnected ;
980
1022
}
1023
+ #endif
981
1024
982
1025
// NOT IMPLEMENTED for other platforms
983
1026
return false ;
984
1027
}
985
-
1028
+
986
1029
987
1030
988
1031
@@ -991,13 +1034,15 @@ public static bool IsPluggedIn(int controllerNumber)
991
1034
////
992
1035
993
1036
// ------------ Members --------------- //
994
-
1037
+
1038
+ // Windows only subsystem
1039
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
995
1040
private static GamePadState [ ] xInputCtrlrs = new GamePadState [ 4 ] ;
996
1041
private static GamePadState [ ] xInputCtrlrsPrev = new GamePadState [ 4 ] ;
997
1042
private static int xiPrevFrameCount = - 1 ;
998
1043
private static bool xiUpdateAlreadyCalled = false ;
999
1044
private static bool xiNumOfCtrlrsQueried = false ;
1000
-
1045
+ #endif
1001
1046
1002
1047
// ------------ Methods --------------- //
1003
1048
@@ -1533,7 +1578,8 @@ private static string DetermineDPadWirelessLinux(XboxDPad padDir, int ctrlrNum)
1533
1578
1534
1579
1535
1580
// ------------- Private XInput Wrappers (for Windows Native player and editor only) -------------- //
1536
-
1581
+
1582
+ #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
1537
1583
1538
1584
//>> For updating states <<
1539
1585
@@ -1712,6 +1758,10 @@ private static float XInputApplyDeadzone(float rawAxisValue, XboxAxis axis, Xbox
1712
1758
1713
1759
return finalValue ;
1714
1760
}
1761
+ #endif
1762
+
1763
+ // END of Windows only subsystem
1764
+
1715
1765
1716
1766
1717
1767
// -------------------------- Handler Script -------------------
@@ -1833,5 +1883,9 @@ public static XboxDPad ToDPad(this XboxButton button)
1833
1883
return XboxDPad . Right ;
1834
1884
return default ( XboxDPad ) ;
1835
1885
}
1886
+
1887
+
1836
1888
}
1889
+
1890
+
1837
1891
}
0 commit comments