コード例 #1
0
        public static void HotPatch()
        {
            var compiler = new UnityCompiler();

            if (!compiler.InvokeCompiler())
            {
                Debug.LogError("Failed to compile assembly.");
                return;
            }

            var assemblyPath = compiler.OutputAssemblyPath;

            hotPatcher.HotPatch(assemblyPath);
        }
コード例 #2
0
        public static void HotPatch(string assemblyName)
        {
            if (!EditorApplication.isPlaying)
            {
                return;
            }

            try {
                if (patcher == null)
                {
                    patcher = new ILDynaRec.HotPatcher();
                    LoadAllAssemblies();
                }

                var checkAssemblies = loadedAssemblies.ToArray();
                if (assemblyName != null)
                {
                    checkAssemblies = checkAssemblies.Where((name) => name == assemblyName).ToArray();
                }

                int i = 0;
                foreach (var assembly in checkAssemblies)
                {
                    if (EditorUtility.DisplayCancelableProgressBar("Hot patching", $"Compiling {assembly}", (float)(i++) / checkAssemblies.Length))
                    {
                        throw new UnityException("Hotpatch cancelled");
                    }

                    var compiler = new UnityCompiler {
                        assemblyModifiedTime = assemblyTimestamps[assembly],
                    };
                    var outputName = Path.GetFileNameWithoutExtension(assembly) + "--hotpatch.dll";
                    if (!compiler.InvokeCompiler(assembly, outputName))
                    {
                        UnityCompiler.Trace($"Did not compile compile {assembly}.");
                        continue;
                    }

                    UnityCompiler.Trace($"Compiled assembly {assembly} as {compiler.OutputAssemblyPath}, running hot patcher.");
                    patcher.HotPatch(compiler.OutputAssemblyPath);
                    assemblyTimestamps[assembly] = DateTime.Now;
                }
            }
            finally {
                EditorUtility.ClearProgressBar();
            }
        }