Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 3762d14

Browse files
committed
Fix InputSystem for IL2CPP
1 parent 3628f3d commit 3762d14

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/Core/Input/InputSystem.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ public void AddUIInputModule()
163163

164164
var assetType = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionAsset");
165165
m_newInputModule = RuntimeProvider.Instance.AddComponent<BaseInputModule>(UIManager.CanvasRoot, TInputSystemUIInputModule);
166-
var asset = RuntimeProvider.Instance.CreateScriptable(assetType);
166+
var asset = RuntimeProvider.Instance.CreateScriptable(assetType)
167+
.Cast(assetType);
167168

168169
inputExtensions = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionSetupExtensions");
169170

170171
var addMap = inputExtensions.GetMethod("AddActionMap", new Type[] { assetType, typeof(string) });
171-
var map = addMap.Invoke(null, new object[] { asset, "UI" });
172+
var map = addMap.Invoke(null, new object[] { asset, "UI" })
173+
.Cast(ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionMap"));
172174

173175
CreateAction(map, "point", new[] { "<Mouse>/position" }, "point");
174176
CreateAction(map, "click", new[] { "<Mouse>/leftButton" }, "leftClick");
@@ -186,23 +188,25 @@ public void AddUIInputModule()
186188

187189
private void CreateAction(object map, string actionName, string[] bindings, string propertyName)
188190
{
191+
var inputActionType = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputAction");
189192
var addAction = inputExtensions.GetMethod("AddAction");
190-
var pointAction = addAction.Invoke(null, new object[] { map, actionName, default, null, null, null, null, null });
193+
var action = addAction.Invoke(null, new object[] { map, actionName, default, null, null, null, null, null })
194+
.Cast(inputActionType);
191195

192-
var inputActionType = pointAction.GetType();
193196
var addBinding = inputExtensions.GetMethod("AddBinding",
194197
new Type[] { inputActionType, typeof(string), typeof(string), typeof(string), typeof(string) });
195198

196199
foreach (string binding in bindings)
197-
addBinding.Invoke(null, new object[] { pointAction, binding, null, null, null });
200+
addBinding.Invoke(null, new object[] { action.Cast(inputActionType), binding, null, null, null });
198201

199-
var inputRef = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionReference")
200-
.GetMethod("Create")
201-
.Invoke(null, new object[] { pointAction });
202+
var refType = ReflectionUtility.GetTypeByName("UnityEngine.InputSystem.InputActionReference");
203+
var inputRef = refType.GetMethod("Create")
204+
.Invoke(null, new object[] { action })
205+
.Cast(refType);
202206

203207
TInputSystemUIInputModule
204208
.GetProperty(propertyName)
205-
.SetValue(m_newInputModule, inputRef, null);
209+
.SetValue(m_newInputModule.Cast(TInputSystemUIInputModule), inputRef, null);
206210
}
207211

208212
public void ActivateModule()

0 commit comments

Comments
 (0)