コード例 #1
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));
        }
コード例 #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);
            var      otherAssemblies     = Directory.GetFiles(ProjectLibrary.ResourceFolder, "*.dll", SearchOption.AllDirectories).ToList(); //TODO: Make platform-agnostic.

            if (type == ScriptAssemblyType.Game)
            {
                assemblyFolders = new string[otherAssemblies.Count + 2];
                assemblies      = new string[frameworkAssemblies.Length + otherAssemblies.Count + 1];

                //TODO: Remove duplicate folders.
                {
                    int i = 0;
                    foreach (var otherAssembly in otherAssemblies)
                    {
                        assemblyFolders[i] = Path.GetDirectoryName(otherAssembly);
                        assemblies[i]      = Path.GetFileNameWithoutExtension(otherAssembly);
                        ++i;
                    }
                }
                assemblyFolders[assemblyFolders.Length - 2] = builtinAssemblyPath;
                assemblyFolders[assemblyFolders.Length - 1] = EditorApplication.FrameworkAssemblyPath;

                /*foreach (var assemblyFolder in assemblyFolders)
                 * {
                 *  //Debug.Print(assemblyFolder);
                 *  BansheeEngine.Debug.Log(assemblyFolder);
                 * }*/


                //otherAssemblies.CopyTo(assemblies, 0);
                assemblies[assemblies.Length - 1] = EditorApplication.EngineAssemblyName;

                outputFile = Path.Combine(outputDir, EditorApplication.ScriptGameAssemblyName);
            }
            else
            {
                assemblyFolders = new string[otherAssemblies.Count + 3];
                assemblies      = new string[frameworkAssemblies.Length + otherAssemblies.Count + 3];

                //TODO: Remove duplicate folders.
                {
                    int i = 0;
                    foreach (var otherAssembly in otherAssemblies)
                    {
                        assemblyFolders[i] = Path.GetDirectoryName(otherAssembly);
                        assemblies[i]      = Path.GetFileNameWithoutExtension(otherAssembly);
                        ++i;
                    }
                }
                assemblyFolders[assemblyFolders.Length - 3] = builtinAssemblyPath;
                assemblyFolders[assemblyFolders.Length - 2] = EditorApplication.FrameworkAssemblyPath;
                assemblyFolders[assemblyFolders.Length - 1] = EditorApplication.ScriptAssemblyPath;

                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, 0, assemblies, otherAssemblies.Count, frameworkAssemblies.Length);

            string defines = BuildManager.GetDefines(platform);

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