2
2
using System . Reflection ;
3
3
using UnityExplorer . Helpers ;
4
4
using UnityEngine ;
5
+ using UnityEngine . EventSystems ;
6
+ using UnityExplorer . UI ;
7
+ using System . Collections . Generic ;
5
8
6
9
namespace UnityExplorer . Input
7
10
{
@@ -64,24 +67,46 @@ public InputSystem()
64
67
private static PropertyInfo m_positionProp ;
65
68
private static MethodInfo m_readVector2InputMethod ;
66
69
67
- public Vector2 MousePosition => ( Vector2 ) m_readVector2InputMethod . Invoke ( MousePositionInfo , new object [ 0 ] ) ;
68
-
69
- public bool GetKeyDown ( KeyCode key )
70
+ public Vector2 MousePosition
70
71
{
71
- var parsedKey = Enum . Parse ( TKey , key . ToString ( ) ) ;
72
- var actualKey = m_kbIndexer . GetValue ( CurrentKeyboard , new object [ ] { parsedKey } ) ;
73
-
74
- return ( bool ) m_btnWasPressedProp . GetValue ( actualKey , null ) ;
72
+ get
73
+ {
74
+ try
75
+ {
76
+ return ( Vector2 ) m_readVector2InputMethod . Invoke ( MousePositionInfo , new object [ 0 ] ) ;
77
+ }
78
+ catch
79
+ {
80
+ return Vector2 . zero ;
81
+ }
82
+ }
75
83
}
76
84
77
- public bool GetKey ( KeyCode key )
85
+ internal static Dictionary < KeyCode , object > ActualKeyDict = new Dictionary < KeyCode , object > ( ) ;
86
+
87
+ internal object GetActualKey ( KeyCode key )
78
88
{
79
- var parsed = Enum . Parse ( TKey , key . ToString ( ) ) ;
80
- var actualKey = m_kbIndexer . GetValue ( CurrentKeyboard , new object [ ] { parsed } ) ;
89
+ if ( ! ActualKeyDict . ContainsKey ( key ) )
90
+ {
91
+ var s = key . ToString ( ) ;
92
+ if ( s . Contains ( "Control" ) )
93
+ s = s . Replace ( "Control" , "Ctrl" ) ;
94
+ else if ( s . Contains ( "Return" ) )
95
+ s = "Enter" ;
81
96
82
- return ( bool ) m_btnIsPressedProp . GetValue ( actualKey , null ) ;
97
+ var parsed = Enum . Parse ( TKey , s ) ;
98
+ var actualKey = m_kbIndexer . GetValue ( CurrentKeyboard , new object [ ] { parsed } ) ;
99
+
100
+ ActualKeyDict . Add ( key , actualKey ) ;
101
+ }
102
+
103
+ return ActualKeyDict [ key ] ;
83
104
}
84
105
106
+ public bool GetKeyDown ( KeyCode key ) => ( bool ) m_btnWasPressedProp . GetValue ( GetActualKey ( key ) , null ) ;
107
+
108
+ public bool GetKey ( KeyCode key ) => ( bool ) m_btnIsPressedProp . GetValue ( GetActualKey ( key ) , null ) ;
109
+
85
110
public bool GetMouseButtonDown ( int btn )
86
111
{
87
112
switch ( btn )
@@ -103,5 +128,44 @@ public bool GetMouseButton(int btn)
103
128
default : throw new NotImplementedException ( ) ;
104
129
}
105
130
}
131
+
132
+ // UI Input
133
+
134
+ //public Type TInputSystemUIInputModule
135
+ // => m_tUIInputModule
136
+ // ?? (m_tUIInputModule = ReflectionHelpers.GetTypeByName("UnityEngine.InputSystem.UI.InputSystemUIInputModule"));
137
+ //internal Type m_tUIInputModule;
138
+
139
+ public BaseInputModule UIModule => null ; // m_newInputModule;
140
+ //internal BaseInputModule m_newInputModule;
141
+
142
+ public PointerEventData InputPointerEvent => null ;
143
+
144
+ public void AddUIInputModule ( )
145
+ {
146
+ // if (TInputSystemUIInputModule != null)
147
+ // {
148
+ //#if CPP
149
+ // // m_newInputModule = UIManager.CanvasRoot.AddComponent(Il2CppType.From(TInputSystemUIInputModule)).TryCast<BaseInputModule>();
150
+ //#else
151
+ // m_newInputModule = (BaseInputModule)UIManager.CanvasRoot.AddComponent(TInputSystemUIInputModule);
152
+ //#endif
153
+ // }
154
+ // else
155
+ // {
156
+ // ExplorerCore.LogWarning("New input system: Could not find type by name 'UnityEngine.InputSystem.UI.InputSystemUIInputModule'");
157
+ // }
158
+ }
159
+
160
+ public void ActivateModule ( )
161
+ {
162
+ //#if CPP
163
+ // // m_newInputModule.ActivateModule();
164
+ //#else
165
+ // m_newInputModule.ActivateModule();
166
+ //#endif
167
+
168
+
169
+ }
106
170
}
107
171
}
0 commit comments