Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a new script code manager.
        /// </summary>
        internal ScriptCodeManager()
        {
            ProjectLibrary.OnEntryAdded    += OnEntryAdded;
            ProjectLibrary.OnEntryRemoved  += OnEntryRemoved;
            ProjectLibrary.OnEntryImported += OnEntryImported;

            // Check for missing or out of date assemblies
            DateTime lastModifiedGameScript   = DateTime.MinValue;
            DateTime lastModifiedEditorScript = DateTime.MinValue;

            LibraryEntry[] scriptEntries = ProjectLibrary.Search("*.cs", new ResourceType[] { ResourceType.ScriptCode });
            for (int i = 0; i < scriptEntries.Length; i++)
            {
                if (scriptEntries[i].Type != LibraryEntryType.File)
                {
                    continue;
                }

                FileEntry fileEntry = (FileEntry)scriptEntries[i];

                string absPath             = Path.Combine(ProjectLibrary.ResourceFolder, fileEntry.Path);
                ScriptCodeImportOptions io = (ScriptCodeImportOptions)fileEntry.Options;
                if (io.EditorScript)
                {
                    lastModifiedEditorScript = File.GetLastWriteTime(absPath);
                }
                else
                {
                    lastModifiedGameScript = File.GetLastWriteTime(absPath);
                }
            }

            DateTime lastCompileTime = new DateTime(EditorApplication.PersistentData.lastCompileTime);

            if (lastModifiedGameScript != DateTime.MinValue)
            {
                string gameAssemblyPath = Path.Combine(EditorApplication.ScriptAssemblyPath,
                                                       EditorApplication.ScriptGameAssemblyName);

                isGameAssemblyDirty = (!File.Exists(gameAssemblyPath) ||
                                       File.GetLastWriteTime(gameAssemblyPath) < lastModifiedGameScript) &&
                                      (lastModifiedGameScript > lastCompileTime);
            }

            if (lastModifiedEditorScript != DateTime.MinValue)
            {
                string editorAssemblyPath = Path.Combine(EditorApplication.ScriptAssemblyPath,
                                                         EditorApplication.ScriptEditorAssemblyName);

                isEditorAssemblyDirty = (!File.Exists(editorAssemblyPath) ||
                                         File.GetLastWriteTime(editorAssemblyPath) < lastModifiedEditorScript) &&
                                        (lastModifiedEditorScript > lastCompileTime);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts compilation of the script files in the project for the specified assembly for the specified platform.
        /// </summary>
        /// <param name="type">Type of the assembly to compile. This determines which script files are used as input.</param>
        /// <param name="platform">Platform to compile the assemblies for.</param>
        /// <param name="debug">Determines should the assemblies contain debug information.</param>
        /// <param name="outputDir">Absolute path to the directory where to output the assemblies.</param>
        /// <returns>Compiler instance that contains the compiler process. Caller must ensure to properly dispose
        ///          of this object when done.</returns>
        public static CompilerInstance CompileAsync(ScriptAssemblyType type, PlatformType platform, bool debug, string outputDir)
        {
            LibraryEntry[] scriptEntries = ProjectLibrary.Search("*", new ResourceType[] { ResourceType.ScriptCode });

            List <string> scriptFiles = new List <string>();

            for (int i = 0; i < scriptEntries.Length; i++)
            {
                if (scriptEntries[i].Type != LibraryEntryType.File)
                {
                    continue;
                }

                FileEntry fileEntry = (FileEntry)scriptEntries[i];

                ScriptCodeImportOptions io = (ScriptCodeImportOptions)fileEntry.Options;
                if (io.EditorScript && type == ScriptAssemblyType.Editor ||
                    !io.EditorScript && type == ScriptAssemblyType.Game)
                {
                    scriptFiles.Add(Path.Combine(ProjectLibrary.ResourceFolder, scriptEntries[i].Path));
                }
            }

            string[] assemblyFolders;
            string[] assemblies;
            string   outputFile;

            string builtinAssemblyPath = debug
                    ? EditorApplication.BuiltinDebugAssemblyPath
                    : EditorApplication.BuiltinReleaseAssemblyPath;

            string[] frameworkAssemblies = BuildManager.GetFrameworkAssemblies(platform);
            if (type == ScriptAssemblyType.Game)
            {
                assemblyFolders = new string[]
                {
                    builtinAssemblyPath,
                    EditorApplication.FrameworkAssemblyPath
                };

                assemblies = new string[frameworkAssemblies.Length + 1];
                assemblies[assemblies.Length - 1] = EditorApplication.EngineAssemblyName;

                outputFile = Path.Combine(outputDir, EditorApplication.ScriptGameAssemblyName);
            }
            else
            {
                assemblyFolders = new string[]
                {
                    builtinAssemblyPath,
                    EditorApplication.FrameworkAssemblyPath,
                    EditorApplication.ScriptAssemblyPath
                };

                assemblies = new string[frameworkAssemblies.Length + 3];
                assemblies[assemblies.Length - 1] = EditorApplication.EngineAssemblyName;
                assemblies[assemblies.Length - 2] = EditorApplication.EditorAssemblyName;
                assemblies[assemblies.Length - 3] = EditorApplication.ScriptGameAssemblyName;

                outputFile = Path.Combine(outputDir, EditorApplication.ScriptEditorAssemblyName);
            }

            Array.Copy(frameworkAssemblies, assemblies, frameworkAssemblies.Length);

            string defines = BuildManager.GetDefines(platform);

            return(new CompilerInstance(scriptFiles.ToArray(), defines, assemblyFolders, assemblies, debug, outputFile));
        }