/// <summary> /// 启动热更实例,包括跨域函数注册、跨域类装配器注册、重定向方法注册 /// </summary> public void Start() { if (IsStart) { return; } else { } IsStart = true; IHotFixConfig config = this.GetAppILRuntime().GetHotFixConfig(); config.RegisterMethods?.Invoke(ILAppDomain);//注册函数适配器 CrossBindingAdaptor[] list = config.Adapters; int max = list == default ? 0 : list.Length; for (int i = 0; i < max; i++) { ILAppDomain.RegisterCrossBindingAdaptor(list[i]);//注册跨域类适配器 } #if ILRUNTIME LitJson.JsonMapper.RegisterILRuntimeCLRRedirection(ILAppDomain); //注册热更端JSON解析器 #endif ILRuntime.Runtime.Generated.CLRBindings.Initialize(ILAppDomain); //注册重定向的方法 }
public static void InitInEditor() { string className = "AppHotFixConfig"; try { ILRuntimeAppEditor app = ILRuntimeAppEditor.GetInstance(); System.Type type = System.Type.GetType(className); IHotFixConfig config = type.Assembly.CreateInstance(className) as IHotFixConfig; config.ToString(); ILRuntimeHotFix hotFix = new ILRuntimeHotFix(app); app.SetHotFixSetting(hotFix, config); } catch (System.Exception _) { UnityEngine.Debug.LogError("未定义必需的热更配置 AppHotFixConfig,或热更配置对象为实现 IILuntimeHotFixConfig 接口"); } }
private static void OnGenerateAdapter(AppDomain domain, string path) { ILRuntimeAppEditor app = ILRuntimeAppEditor.GetInstance(); IHotFixConfig config = app.GetHotFixConfig(); string[] splits = path.Split('.'); splits = splits[0].Split('/'); string name = splits[splits.Length - 1]; string code = string.Empty; var className = config.AutoAdapterGenerates; bool hasAdapterConfig = false; foreach (var item in className) { if (item.Key == name) { hasAdapterConfig = true; if (path.Contains(".cs")) { using (StreamWriter sw = new StreamWriter(path)) { sw.WriteLine(CrossBindingCodeGenerator.GenerateCrossBindingAdapterCode(item.Value, config.SpaceName)); } } else { string info = string.Format("选定的文件 {0} 不是cs代码文件", path); EditorUtility.DisplayDialog("生成错误", info, "朕知道了"); throw new Exception(info); } } } if (!hasAdapterConfig) { string info = "选定的文件可能未包含在适配器的配置中,请通过修改 AppHotFixConfigBase 或其子类中的 GetAutoAdapterGenerates() 方法增加定义之后重试"; EditorUtility.DisplayDialog("生成错误", info, "朕知道了"); throw new Exception(info); } }
public void SetHotFixSetting(ILRuntimeHotFix value, IHotFixConfig config) { ILRuntimeHotFix = value; Config = config; }