private static IRemoteTechAPIv1 InitializeAPI() { var loadedAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name.Equals(REMOTE_TECH_ASSEMBLY)); if (loadedAssembly == null) return null; var type = loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(REMOTE_TECH_API)); if (type == null) return null; var methods = type.GetMethods(); var api = new RemoteTechAPI(); try { foreach (var property in api.GetType().GetProperties()) { var method = methods.FirstOrDefault(m => { UnityEngine.Debug.Log(m.Name); return m.Name.Equals(property.Name); }); if (method == null) throw new ArgumentNullException(property.Name); var del = Delegate.CreateDelegate(property.PropertyType, type, method.Name); property.SetValue(api, del, null); } } catch (Exception e) { UnityEngine.Debug.Log("kOS: Error creating RemoteTech2 interface: " + e); return null; } UnityEngine.Debug.Log("kOS: RemoteTech2 interface successfully created."); return api; }
private static IRemoteTechAPIv1 InitializeAPI() { var loadedAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.assembly.GetName().Name.Equals(REMOTE_TECH_ASSEMBLY)); if (loadedAssembly == null) { return(null); } var type = loadedAssembly.assembly.GetTypes().FirstOrDefault(t => t.FullName.Equals(REMOTE_TECH_API)); if (type == null) { return(null); } var methods = type.GetMethods(); var api = new RemoteTechAPI(); try { foreach (var property in api.GetType().GetProperties()) { var method = methods.FirstOrDefault(m => { UnityEngine.Debug.Log(m.Name); return(m.Name.Equals(property.Name)); }); if (method == null) { throw new ArgumentNullException(property.Name); } var del = Delegate.CreateDelegate(property.PropertyType, type, method.Name); property.SetValue(api, del, null); } } catch (Exception e) { UnityEngine.Debug.Log("kOS: Error creating RemoteTech2 interface: " + e); return(null); } UnityEngine.Debug.Log("kOS: RemoteTech2 interface successfully created."); return(api); }