Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }
        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();
            }
        }
        static void LoadAllAssemblies()
        {
            EditorUtility.DisplayCancelableProgressBar("Hot patching", "Initial assembly load", 0.0f);

            var dir       = new DirectoryInfo(ScriptAssembliesDir);
            var fileInfos = dir.GetFileSystemInfos("*.dll");

            int i = 0;

            foreach (var fileInfo in fileInfos)
            {
                if (EditorUtility.DisplayCancelableProgressBar("Hot patching", $"Analysing {fileInfo.Name}", (float)(i++) / fileInfos.Length))
                {
                    throw new UnityException("Hotpatch cancelled");
                }
                patcher.LoadLocalAssembly(fileInfo.FullName);
                loadedAssemblies.Add(fileInfo.Name);
                assemblyTimestamps[fileInfo.Name] = fileInfo.LastWriteTime;
                UnityCompiler.Trace($"Read {fileInfo.Name} ({fileInfo.FullName})");
            }
        }