@@ -29,11 +29,16 @@ public static IInputSystem Current
2929 {
3030 try
3131 {
32- try
33- {
34- _current = new LegacyInputSystem ( ) ;
35- XuaLogger . AutoTranslator . Debug ( "[UnityInput] Using LegacyInputSystem" ) ;
36- }
32+ try
33+ {
34+ #if IL2CPP
35+ _current = new Il2CppLegacyInputSystem ( ) ;
36+ XuaLogger . AutoTranslator . Debug ( "[UnityInput] Using Il2CppLegacyInputSystem" ) ;
37+ #else
38+ _current = new LegacyInputSystem ( ) ;
39+ XuaLogger . AutoTranslator . Debug ( "[UnityInput] Using LegacyInputSystem" ) ;
40+ #endif
41+ }
3742 catch
3843 {
3944 var newInputSystem = new NewInputSystem ( ) ;
@@ -54,7 +59,11 @@ public static IInputSystem Current
5459 /// <summary>
5560 /// True if the Input class is not disabled.
5661 /// </summary>
62+ #if IL2CPP
63+ public bool LegacyInputSystemAvailable => Current is Il2CppLegacyInputSystem ;
64+ #else
5765 public bool LegacyInputSystemAvailable => Current is LegacyInputSystem ;
66+ #endif
5867 }
5968
6069 /// <summary>
@@ -894,4 +903,141 @@ internal class LegacyInputSystem : IInputSystem
894903
895904 public IEnumerable < KeyCode > SupportedKeyCodes { get ; } = ( KeyCode [ ] ) Enum . GetValues ( typeof ( KeyCode ) ) ;
896905 }
906+
907+ #if IL2CPP
908+ internal class Il2CppLegacyInputSystem : IInputSystem
909+ {
910+ private Type GetInputType ( )
911+ {
912+ var type = XUnity . Common . Constants . UnityTypes . Input ? . ClrType ;
913+ if ( type == null ) throw new InvalidOperationException ( "Failed to find the UnityEngine.Input type" ) ;
914+ return type ;
915+ }
916+
917+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
918+ public Il2CppLegacyInputSystem ( ) => GetKeyDown ( KeyCode . A ) ;
919+
920+ private System . Reflection . MethodInfo _getKeyString ;
921+ public bool GetKey ( string name )
922+ {
923+ if ( _getKeyString == null ) _getKeyString = GetInputType ( ) . GetMethod ( "GetKey" , new [ ] { typeof ( string ) } ) ;
924+ return _getKeyString != null && ( bool ) _getKeyString . Invoke ( null , new object [ ] { name } ) ;
925+ }
926+
927+ private System . Reflection . MethodInfo _getKey ;
928+ public bool GetKey ( KeyCode key )
929+ {
930+ if ( _getKey == null ) _getKey = GetInputType ( ) . GetMethod ( "GetKey" , new [ ] { typeof ( KeyCode ) } ) ;
931+ return _getKey != null && ( bool ) _getKey . Invoke ( null , new object [ ] { key } ) ;
932+ }
933+
934+ private System . Reflection . MethodInfo _getKeyDownString ;
935+ public bool GetKeyDown ( string name )
936+ {
937+ if ( _getKeyDownString == null ) _getKeyDownString = GetInputType ( ) . GetMethod ( "GetKeyDown" , new [ ] { typeof ( string ) } ) ;
938+ return _getKeyDownString != null && ( bool ) _getKeyDownString . Invoke ( null , new object [ ] { name } ) ;
939+ }
940+
941+ private System . Reflection . MethodInfo _getKeyDown ;
942+ public bool GetKeyDown ( KeyCode key )
943+ {
944+ if ( _getKeyDown == null ) _getKeyDown = GetInputType ( ) . GetMethod ( "GetKeyDown" , new [ ] { typeof ( KeyCode ) } ) ;
945+ return _getKeyDown != null && ( bool ) _getKeyDown . Invoke ( null , new object [ ] { key } ) ;
946+ }
947+
948+ private System . Reflection . MethodInfo _getKeyUpString ;
949+ public bool GetKeyUp ( string name )
950+ {
951+ if ( _getKeyUpString == null ) _getKeyUpString = GetInputType ( ) . GetMethod ( "GetKeyUp" , new [ ] { typeof ( string ) } ) ;
952+ return _getKeyUpString != null && ( bool ) _getKeyUpString . Invoke ( null , new object [ ] { name } ) ;
953+ }
954+
955+ private System . Reflection . MethodInfo _getKeyUp ;
956+ public bool GetKeyUp ( KeyCode key )
957+ {
958+ if ( _getKeyUp == null ) _getKeyUp = GetInputType ( ) . GetMethod ( "GetKeyUp" , new [ ] { typeof ( KeyCode ) } ) ;
959+ return _getKeyUp != null && ( bool ) _getKeyUp . Invoke ( null , new object [ ] { key } ) ;
960+ }
961+
962+ private System . Reflection . MethodInfo _getMouseButton ;
963+ public bool GetMouseButton ( int button )
964+ {
965+ if ( _getMouseButton == null ) _getMouseButton = GetInputType ( ) . GetMethod ( "GetMouseButton" , new [ ] { typeof ( int ) } ) ;
966+ return _getMouseButton != null && ( bool ) _getMouseButton . Invoke ( null , new object [ ] { button } ) ;
967+ }
968+
969+ private System . Reflection . MethodInfo _getMouseButtonDown ;
970+ public bool GetMouseButtonDown ( int button )
971+ {
972+ if ( _getMouseButtonDown == null ) _getMouseButtonDown = GetInputType ( ) . GetMethod ( "GetMouseButtonDown" , new [ ] { typeof ( int ) } ) ;
973+ return _getMouseButtonDown != null && ( bool ) _getMouseButtonDown . Invoke ( null , new object [ ] { button } ) ;
974+ }
975+
976+ private System . Reflection . MethodInfo _getMouseButtonUp ;
977+ public bool GetMouseButtonUp ( int button )
978+ {
979+ if ( _getMouseButtonUp == null ) _getMouseButtonUp = GetInputType ( ) . GetMethod ( "GetMouseButtonUp" , new [ ] { typeof ( int ) } ) ;
980+ return _getMouseButtonUp != null && ( bool ) _getMouseButtonUp . Invoke ( null , new object [ ] { button } ) ;
981+ }
982+
983+ private System . Reflection . MethodInfo _resetInputAxes ;
984+ public void ResetInputAxes ( )
985+ {
986+ if ( _resetInputAxes == null ) _resetInputAxes = GetInputType ( ) . GetMethod ( "ResetInputAxes" , Type . EmptyTypes ) ;
987+ _resetInputAxes ? . Invoke ( null , null ) ;
988+ }
989+
990+ private System . Reflection . PropertyInfo _mousePosition ;
991+ public Vector3 mousePosition
992+ {
993+ get
994+ {
995+ if ( _mousePosition == null ) _mousePosition = GetInputType ( ) . GetProperty ( "mousePosition" ) ;
996+ return _mousePosition != null ? ( Vector3 ) _mousePosition . GetValue ( null , null ) : Vector3 . zero ;
997+ }
998+ }
999+
1000+ private System . Reflection . PropertyInfo _mouseScrollDelta ;
1001+ public Vector2 mouseScrollDelta
1002+ {
1003+ get
1004+ {
1005+ if ( _mouseScrollDelta == null ) _mouseScrollDelta = GetInputType ( ) . GetProperty ( "mouseScrollDelta" ) ;
1006+ return _mouseScrollDelta != null ? ( Vector2 ) _mouseScrollDelta . GetValue ( null , null ) : Vector2 . zero ;
1007+ }
1008+ }
1009+
1010+ private System . Reflection . PropertyInfo _mousePresent ;
1011+ public bool mousePresent
1012+ {
1013+ get
1014+ {
1015+ if ( _mousePresent == null ) _mousePresent = GetInputType ( ) . GetProperty ( "mousePresent" ) ;
1016+ return _mousePresent != null && ( bool ) _mousePresent . GetValue ( null , null ) ;
1017+ }
1018+ }
1019+
1020+ private System . Reflection . PropertyInfo _anyKey ;
1021+ public bool anyKey
1022+ {
1023+ get
1024+ {
1025+ if ( _anyKey == null ) _anyKey = GetInputType ( ) . GetProperty ( "anyKey" ) ;
1026+ return _anyKey != null && ( bool ) _anyKey . GetValue ( null , null ) ;
1027+ }
1028+ }
1029+
1030+ private System . Reflection . PropertyInfo _anyKeyDown ;
1031+ public bool anyKeyDown
1032+ {
1033+ get
1034+ {
1035+ if ( _anyKeyDown == null ) _anyKeyDown = GetInputType ( ) . GetProperty ( "anyKeyDown" ) ;
1036+ return _anyKeyDown != null && ( bool ) _anyKeyDown . GetValue ( null , null ) ;
1037+ }
1038+ }
1039+
1040+ public IEnumerable < KeyCode > SupportedKeyCodes { get ; } = ( KeyCode [ ] ) Enum . GetValues ( typeof ( KeyCode ) ) ;
1041+ }
1042+ #endif
8971043}
0 commit comments