Skip to content

Commit d25cf68

Browse files
authored
Use UnityInput to support both legacy and new input systems (#804)
Copied from BepInEx to keep support for other plugin loaders.
1 parent a0cc044 commit d25cf68

File tree

9 files changed

+943
-37
lines changed

9 files changed

+943
-37
lines changed

libs/Proxies/Unity.InputSystem.dll

2.61 MB
Binary file not shown.

libs/Unity.InputSystem.dll

327 KB
Binary file not shown.

src/XUnity.AutoTranslator.Plugin.Core/AutoTranslationPlugin.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,61 +2759,61 @@ private void HandleInputSafe()
27592759

27602760
private void HandleInput()
27612761
{
2762-
var isAltPressed = Input.GetKey( KeyCode.LeftAlt ) || Input.GetKey( KeyCode.RightAlt );
2762+
var isAltPressed = UnityInput.Current.GetKey( KeyCode.LeftAlt ) || UnityInput.Current.GetKey( KeyCode.RightAlt );
27632763
if( isAltPressed )
27642764
{
2765-
var isCtrlPressed = Input.GetKey( KeyCode.LeftControl );
2765+
var isCtrlPressed = UnityInput.Current.GetKey( KeyCode.LeftControl );
27662766

2767-
if( Input.GetKeyDown( KeyCode.T ) )
2767+
if( UnityInput.Current.GetKeyDown( KeyCode.T ) )
27682768
{
27692769
ToggleTranslation();
27702770
}
2771-
else if( Input.GetKeyDown( KeyCode.F ) )
2771+
else if( UnityInput.Current.GetKeyDown( KeyCode.F ) )
27722772
{
27732773
ToggleFont();
27742774
}
2775-
else if( Input.GetKeyDown( KeyCode.R ) )
2775+
else if( UnityInput.Current.GetKeyDown( KeyCode.R ) )
27762776
{
27772777
ReloadTranslations();
27782778
}
2779-
else if( Input.GetKeyDown( KeyCode.U ) )
2779+
else if( UnityInput.Current.GetKeyDown( KeyCode.U ) )
27802780
{
27812781
ManualHook();
27822782
}
2783-
else if( Input.GetKeyDown( KeyCode.Q ) )
2783+
else if( UnityInput.Current.GetKeyDown( KeyCode.Q ) )
27842784
{
27852785
RebootPlugin();
27862786
}
2787-
//else if( Input.GetKeyDown( KeyCode.B ) )
2787+
//else if( UnityInput.Current.GetKeyDown( KeyCode.B ) )
27882788
//{
27892789
// ConnectionTrackingWebClient.CloseServicePoints();
27902790
//}
2791-
else if( Input.GetKeyDown( KeyCode.Alpha0 ) || Input.GetKeyDown( KeyCode.Keypad0 ) )
2791+
else if( UnityInput.Current.GetKeyDown( KeyCode.Alpha0 ) || UnityInput.Current.GetKeyDown( KeyCode.Keypad0 ) )
27922792
{
27932793
if( MainWindow != null )
27942794
{
27952795
MainWindow.IsShown = !MainWindow.IsShown;
27962796
}
27972797
}
2798-
else if( Input.GetKeyDown( KeyCode.Alpha1 ) || Input.GetKeyDown( KeyCode.Keypad1 ) )
2798+
else if( UnityInput.Current.GetKeyDown( KeyCode.Alpha1 ) || UnityInput.Current.GetKeyDown( KeyCode.Keypad1 ) )
27992799
{
28002800
ToggleTranslationAggregator();
28012801
}
28022802
else if( isCtrlPressed )
28032803
{
2804-
if( Input.GetKeyDown( KeyCode.Keypad9 ) )
2804+
if( UnityInput.Current.GetKeyDown( KeyCode.Keypad9 ) )
28052805
{
28062806
Settings.SimulateError = !Settings.SimulateError;
28072807
}
2808-
else if( Input.GetKeyDown( KeyCode.Keypad8 ) )
2808+
else if( UnityInput.Current.GetKeyDown( KeyCode.Keypad8 ) )
28092809
{
28102810
Settings.SimulateDelayedError = !Settings.SimulateDelayedError;
28112811
}
2812-
else if( Input.GetKeyDown( KeyCode.Keypad7 ) )
2812+
else if( UnityInput.Current.GetKeyDown( KeyCode.Keypad7 ) )
28132813
{
28142814
PrintSceneInformation();
28152815
}
2816-
else if( Input.GetKeyDown( KeyCode.Keypad6 ) )
2816+
else if( UnityInput.Current.GetKeyDown( KeyCode.Keypad6 ) )
28172817
{
28182818
PrintObjects();
28192819
}

src/XUnity.AutoTranslator.Plugin.Core/UI/GUIUtil.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text;
55
using UnityEngine;
66
using XUnity.Common.Constants;
7+
using XUnity.Common.Utilities;
78

89
namespace XUnity.AutoTranslator.Plugin.Core.UI
910
{
@@ -174,20 +175,20 @@ public static bool IsAnyMouseButtonOrScrollWheelDownLegacy
174175
{
175176
get
176177
{
177-
return Input.GetMouseButtonDown( 0 )
178-
|| Input.GetMouseButtonDown( 1 )
179-
|| Input.GetMouseButtonDown( 2 );
178+
return UnityInput.Current.GetMouseButtonDown( 0 )
179+
|| UnityInput.Current.GetMouseButtonDown( 1 )
180+
|| UnityInput.Current.GetMouseButtonDown( 2 );
180181
}
181182
}
182183

183184
public static bool IsAnyMouseButtonOrScrollWheelDown
184185
{
185186
get
186187
{
187-
return Input.mouseScrollDelta.y != 0f
188-
|| Input.GetMouseButtonDown( 0 )
189-
|| Input.GetMouseButtonDown( 1 )
190-
|| Input.GetMouseButtonDown( 2 );
188+
return UnityInput.Current.mouseScrollDelta.y != 0f
189+
|| UnityInput.Current.GetMouseButtonDown( 0 )
190+
|| UnityInput.Current.GetMouseButtonDown( 1 )
191+
|| UnityInput.Current.GetMouseButtonDown( 2 );
191192
}
192193
}
193194

@@ -205,20 +206,20 @@ public static bool IsAnyMouseButtonOrScrollWheelLegacy
205206
{
206207
get
207208
{
208-
return Input.GetMouseButton( 0 )
209-
|| Input.GetMouseButton( 1 )
210-
|| Input.GetMouseButton( 2 );
209+
return UnityInput.Current.GetMouseButton( 0 )
210+
|| UnityInput.Current.GetMouseButton( 1 )
211+
|| UnityInput.Current.GetMouseButton( 2 );
211212
}
212213
}
213214

214215
public static bool IsAnyMouseButtonOrScrollWheel
215216
{
216217
get
217218
{
218-
return Input.mouseScrollDelta.y != 0f
219-
|| Input.GetMouseButton( 0 )
220-
|| Input.GetMouseButton( 1 )
221-
|| Input.GetMouseButton( 2 );
219+
return UnityInput.Current.mouseScrollDelta.y != 0f
220+
|| UnityInput.Current.GetMouseButton( 0 )
221+
|| UnityInput.Current.GetMouseButton( 1 )
222+
|| UnityInput.Current.GetMouseButton( 2 );
222223
}
223224
}
224225
}

src/XUnity.AutoTranslator.Plugin.Core/UI/TranslationAggregatorOptionsWindow.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using UnityEngine;
4+
using XUnity.Common.Utilities;
45

56
namespace XUnity.AutoTranslator.Plugin.Core.UI
67
{
@@ -42,7 +43,7 @@ public void OnGUI()
4243

4344
if( GUIUtil.IsAnyMouseButtonOrScrollWheelDownSafe )
4445
{
45-
var point = new Vector2( Input.mousePosition.x, Screen.height - Input.mousePosition.y );
46+
var point = new Vector2( UnityInput.Current.mousePosition.x, Screen.height - UnityInput.Current.mousePosition.y );
4647
_isMouseDownOnWindow = _windowRect.Contains( point );
4748
}
4849

@@ -52,11 +53,11 @@ public void OnGUI()
5253
// make sure window is focused if scroll wheel is used to indicate we consumed that event
5354
GUI.FocusWindow( WindowId );
5455

55-
var point1 = new Vector2( Input.mousePosition.x, Screen.height - Input.mousePosition.y );
56+
var point1 = new Vector2( UnityInput.Current.mousePosition.x, Screen.height - UnityInput.Current.mousePosition.y );
5657
if( !_windowRect.Contains( point1 ) )
5758
return;
5859

59-
Input.ResetInputAxes();
60+
UnityInput.Current.ResetInputAxes();
6061
}
6162

6263
private void CreateWindowUI( int id )

src/XUnity.AutoTranslator.Plugin.Core/UI/TranslationAggregatorWindow.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void OnGUI()
4848

4949
if( GUIUtil.IsAnyMouseButtonOrScrollWheelDownSafe )
5050
{
51-
var point = new Vector2( Input.mousePosition.x, Screen.height - Input.mousePosition.y );
51+
var point = new Vector2( UnityInput.Current.mousePosition.x, Screen.height - UnityInput.Current.mousePosition.y );
5252
_isMouseDownOnWindow = _windowRect.Contains( point );
5353
}
5454

@@ -58,11 +58,11 @@ public void OnGUI()
5858
// make sure window is focused if scroll wheel is used to indicate we consumed that event
5959
GUI.FocusWindow( WindowId );
6060

61-
var point1 = new Vector2( Input.mousePosition.x, Screen.height - Input.mousePosition.y );
61+
var point1 = new Vector2( UnityInput.Current.mousePosition.x, Screen.height - UnityInput.Current.mousePosition.y );
6262
if( !_windowRect.Contains( point1 ) )
6363
return;
6464

65-
Input.ResetInputAxes();
65+
UnityInput.Current.ResetInputAxes();
6666
}
6767

6868
public void Update()

src/XUnity.AutoTranslator.Plugin.Core/UI/XuaWindow.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using XUnity.AutoTranslator.Plugin.Core.Endpoints;
66
using XUnity.AutoTranslator.Plugin.Core.Hooks.UGUI;
7+
using XUnity.Common.Utilities;
78

89
namespace XUnity.AutoTranslator.Plugin.Core.UI
910
{
@@ -39,7 +40,7 @@ public void OnGUI()
3940

4041
if( GUIUtil.IsAnyMouseButtonOrScrollWheelDownSafe )
4142
{
42-
var point = new Vector2( Input.mousePosition.x, Screen.height - Input.mousePosition.y );
43+
var point = new Vector2( UnityInput.Current.mousePosition.x, Screen.height - UnityInput.Current.mousePosition.y );
4344
_isMouseDownOnWindow = _windowRect.Contains( point );
4445
}
4546

@@ -49,11 +50,11 @@ public void OnGUI()
4950
// make sure window is focused if scroll wheel is used to indicate we consumed that event
5051
GUI.FocusWindow( WindowId );
5152

52-
var point1 = new Vector2( Input.mousePosition.x, Screen.height - Input.mousePosition.y );
53+
var point1 = new Vector2( UnityInput.Current.mousePosition.x, Screen.height - UnityInput.Current.mousePosition.y );
5354
if( !_windowRect.Contains( point1 ) )
5455
return;
5556

56-
Input.ResetInputAxes();
57+
UnityInput.Current.ResetInputAxes();
5758
}
5859

5960
private void CreateWindowUI( int id )

0 commit comments

Comments
 (0)