コード例 #1
0
        private ScriptAssembly[] GetAllScriptAssemblies(BuildFlags buildFlags, EditorScriptCompilationOptions options, PrecompiledAssembly[] unityAssembliesArg, PrecompiledAssembly[] precompiledAssembliesArg)
        {
            EditorBuildRules.CompilationAssemblies assemblies = new EditorBuildRules.CompilationAssemblies
            {
                UnityAssemblies          = unityAssembliesArg,
                PrecompiledAssemblies    = precompiledAssembliesArg,
                CustomTargetAssemblies   = this.customTargetAssemblies,
                EditorAssemblyReferences = ModuleUtils.GetAdditionalReferencesForUserScripts()
            };
            ScriptAssemblySettings settings = this.CreateEditorScriptAssemblySettings(options);

            return(EditorBuildRules.GetAllScriptAssemblies(this.allScripts, this.projectDirectory, buildFlags, settings, assemblies));
        }
コード例 #2
0
    private static MonoIsland CreateMonoIsland(SupportedLanguage language)
    {
        const string kInputFilePath     = "Packages/com.unity.inputsystem/InputSystem";
        var          outputAssemblyPath = Path.GetTempFileName();

        var options          = EditorScriptCompilationOptions.BuildingForEditor;
        var buildTarget      = UnityEditor.EditorUserBuildSettings.activeBuildTarget;
        var buildTargetGroup = UnityEditor.EditorUserBuildSettings.activeBuildTargetGroup;
        var defines          = ieu.GetCompilationDefines(options, buildTargetGroup, buildTarget);

        var references = new List <string>();

        references.Add(ieu.GetEngineAssemblyPath());
        references.Add(ieu.GetEngineCoreModuleAssemblyPath());
        references.Add(ieu.GetEditorAssemblyPath());
        references.AddRange(ModuleUtils.GetAdditionalReferencesForUserScripts());
#if UNITY_EDITOR_OSX
        references.Add(Path.Combine(EditorApplication.applicationContentsPath, "UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll"));
#elif UNITY_EDITOR_WIN
        references.Add(Path.Combine(Path.GetDirectoryName(EditorApplication.applicationPath), "Data/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll"));
#endif
        var unityAssemblies = InternalEditorUtility.GetUnityAssemblies(true, buildTargetGroup, buildTarget);
        foreach (var asm in unityAssemblies)
        {
            references.Add(asm.Path);
        }

        var apiCompatibilityLevel = PlayerSettings.GetApiCompatibilityLevel(EditorUserBuildSettings.activeBuildTargetGroup);

        // Hopefully the churn on these mono library helpers is over, this is going to be a bit a pain to
        // always chase.
#if UNITY_2018_3_OR_NEWER && !(UNITY_2019_1_OR_NEWER)
        var scriptAssembly = new ScriptAssembly
        {
            Filename = AssetPath.GetFileName(outputAssemblyPath),
            Flags    = AssemblyFlags.None
        };
        references.AddRange(MonoLibraryHelpers.GetSystemLibraryReferences(apiCompatibilityLevel, buildTarget, language, true, scriptAssembly));
#elif UNITY_2019_1_OR_NEWER
        references.AddRange(MonoLibraryHelpers.GetSystemLibraryReferences(apiCompatibilityLevel, buildTarget, language));
#endif

        var sources = new List <string>();
        sources.AddRange(Directory.GetFiles(kInputFilePath, "*.cs", SearchOption.AllDirectories));

        var island = new MonoIsland(buildTarget, apiCompatibilityLevel, true, sources.ToArray(),
                                    references.ToArray(), defines, outputAssemblyPath);

        return(island);
    }
コード例 #3
0
 public static bool IsInternalAssembly(string file)
 {
     // ISSUE: object of a compiler-generated type is created
     // ISSUE: variable of a compiler-generated type
     AssemblyHelper.\u003CIsInternalAssembly\u003Ec__AnonStorey30 assemblyCAnonStorey30 = new AssemblyHelper.\u003CIsInternalAssembly\u003Ec__AnonStorey30();
     // ISSUE: reference to a compiler-generated field
     assemblyCAnonStorey30.file = file;
     // ISSUE: reference to a compiler-generated field
     if (!ModuleManager.IsRegisteredModule(assemblyCAnonStorey30.file))
     {
         // ISSUE: reference to a compiler-generated method
         return(((IEnumerable <string>)ModuleUtils.GetAdditionalReferencesForUserScripts()).Any <string>(new Func <string, bool>(assemblyCAnonStorey30.\u003C\u003Em__43)));
     }
     return(true);
 }
コード例 #4
0
 public static bool IsInternalAssembly(string file)
 {
     return(ModuleUtils.GetAdditionalReferencesForUserScripts().Any(p => p.Equals(file)));
 }
コード例 #5
0
 public static bool IsInternalAssembly(string file)
 {
     return(UnityEditor.Modules.ModuleManager.IsRegisteredModule(file) ||
            ModuleUtils.GetAdditionalReferencesForUserScripts().Any(p => p.Equals(file)));
 }
コード例 #6
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);
        }