Пример #1
0
 public void StopAllCompilation()
 {
     if (this.compilationTask != null)
     {
         this.compilationTask.Stop();
         this.compilationTask = null;
     }
 }
Пример #2
0
        internal bool CompileScripts(ScriptAssemblySettings scriptAssemblySettings, string tempBuildDirectory, BuildFlags buildflags, ref EditorBuildRules.TargetAssembly[] notCompiledTargetAssemblies)
        {
            this.DeleteUnusedAssemblies();
            this.allScripts.RemoveWhere((string path) => !File.Exists(Path.Combine(this.projectDirectory, path)));
            this.StopAllCompilation();
            if (!Directory.Exists(scriptAssemblySettings.OutputDirectory))
            {
                Directory.CreateDirectory(scriptAssemblySettings.OutputDirectory);
            }
            if (!Directory.Exists(tempBuildDirectory))
            {
                Directory.CreateDirectory(tempBuildDirectory);
            }
            IEnumerable <string> enumerable = (!this.areAllScriptsDirty) ? this.dirtyScripts.ToArray <string>() : this.allScripts.ToArray <string>();

            this.areAllScriptsDirty = false;
            this.dirtyScripts.Clear();
            bool result;

            if (!enumerable.Any <string>() && this.runScriptUpdaterAssemblies.Count == 0)
            {
                result = false;
            }
            else
            {
                EditorBuildRules.CompilationAssemblies assemblies = new EditorBuildRules.CompilationAssemblies
                {
                    UnityAssemblies          = this.unityAssemblies,
                    PrecompiledAssemblies    = this.precompiledAssemblies,
                    CustomTargetAssemblies   = this.customTargetAssemblies,
                    EditorAssemblyReferences = ModuleUtils.GetAdditionalReferencesForUserScripts()
                };
                EditorBuildRules.GenerateChangedScriptAssembliesArgs generateChangedScriptAssembliesArgs = new EditorBuildRules.GenerateChangedScriptAssembliesArgs
                {
                    AllSourceFiles       = this.allScripts,
                    DirtySourceFiles     = enumerable,
                    ProjectDirectory     = this.projectDirectory,
                    BuildFlags           = buildflags,
                    Settings             = scriptAssemblySettings,
                    Assemblies           = assemblies,
                    RunUpdaterAssemblies = this.runScriptUpdaterAssemblies
                };
                ScriptAssembly[] array = EditorBuildRules.GenerateChangedScriptAssemblies(generateChangedScriptAssembliesArgs);
                notCompiledTargetAssemblies = generateChangedScriptAssembliesArgs.NotCompiledTargetAssemblies.ToArray <EditorBuildRules.TargetAssembly>();
                if (!array.Any <ScriptAssembly>())
                {
                    result = false;
                }
                else
                {
                    this.compilationTask = new CompilationTask(array, tempBuildDirectory, buildflags, SystemInfo.processorCount);
                    this.compilationTask.OnCompilationStarted += delegate(ScriptAssembly assembly, int phase)
                    {
                        Console.WriteLine("- Starting compile {0}", Path.Combine(scriptAssemblySettings.OutputDirectory, assembly.Filename));
                    };
                    IEnumerable <MonoIsland> compilingMonoIslands = from i in this.GetAllMonoIslands()
                                                                    where 0 < i._files.Length
                                                                    select i;
                    this.compilationTask.OnCompilationFinished += delegate(ScriptAssembly assembly, List <CompilerMessage> messages)
                    {
                        Console.WriteLine("- Finished compile {0}", Path.Combine(scriptAssemblySettings.OutputDirectory, assembly.Filename));
                        if (this.runScriptUpdaterAssemblies.Contains(assembly.Filename))
                        {
                            this.runScriptUpdaterAssemblies.Remove(assembly.Filename);
                        }
                        if (!messages.Any((CompilerMessage m) => m.type == CompilerMessageType.Error))
                        {
                            string engineAssemblyPath = InternalEditorUtility.GetEngineAssemblyPath();
                            string unityUNet          = EditorApplication.applicationContentsPath + "/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll";
                            if (!Weaver.WeaveUnetFromEditor(compilingMonoIslands, Path.Combine(tempBuildDirectory, assembly.Filename), Path.Combine(EditorCompilation.EditorTempPath, assembly.Filename), engineAssemblyPath, unityUNet, (buildflags & BuildFlags.BuildingForEditor) != BuildFlags.None))
                            {
                                messages.Add(new CompilerMessage
                                {
                                    message = "UNet Weaver failed",
                                    type    = CompilerMessageType.Error,
                                    file    = assembly.FullPath,
                                    line    = -1,
                                    column  = -1
                                });
                                this.StopAllCompilation();
                            }
                            else
                            {
                                EditorCompilation.CopyAssembly(Path.Combine(tempBuildDirectory, assembly.Filename), assembly.FullPath);
                            }
                        }
                    };
                    this.compilationTask.Poll();
                    result = true;
                }
            }
            return(result);
        }