/// <summary>
        /// Triggers required compilation or code editor syncing if needed.
        /// </summary>
        internal void Update()
        {
            if (EditorApplication.HasFocus && CodeEditor.IsSolutionDirty)
            {
                CodeEditor.SyncSolution();
            }

            if (PlayInEditor.State == PlayInEditorState.Stopped && !ProjectLibrary.ImportInProgress)
            {
                if (compilerInstance == null)
                {
                    if (EditorApplication.HasFocus)
                    {
                        string outputDir = EditorApplication.ScriptAssemblyPath;

                        if (isGameAssemblyDirty)
                        {
                            compilerInstance = ScriptCompiler.CompileAsync(
                                ScriptAssemblyType.Game, BuildManager.ActivePlatform, true, outputDir);

                            EditorApplication.SetStatusCompiling(true);
                            EditorApplication.PersistentData.lastCompileTime = DateTime.Now.Ticks;
                            isGameAssemblyDirty = false;
                        }
                        else if (isEditorAssemblyDirty)
                        {
                            compilerInstance = ScriptCompiler.CompileAsync(
                                ScriptAssemblyType.Editor, BuildManager.ActivePlatform, true, outputDir);

                            EditorApplication.SetStatusCompiling(true);
                            EditorApplication.PersistentData.lastCompileTime = DateTime.Now.Ticks;
                            isEditorAssemblyDirty = false;
                        }
                    }
                }
                else
                {
                    if (compilerInstance.IsDone)
                    {
                        Debug.Clear(DebugMessageType.CompilerWarning);
                        Debug.Clear(DebugMessageType.CompilerError);

                        LogWindow window = EditorWindow.GetWindow <LogWindow>();
                        if (window != null)
                        {
                            window.Refresh();
                        }

                        if (compilerInstance.HasErrors)
                        {
                            foreach (var msg in compilerInstance.WarningMessages)
                            {
                                Debug.LogMessage(FormMessage(msg), DebugMessageType.CompilerWarning);
                            }

                            foreach (var msg in compilerInstance.ErrorMessages)
                            {
                                Debug.LogMessage(FormMessage(msg), DebugMessageType.CompilerError);
                            }
                        }

                        compilerInstance.Dispose();
                        compilerInstance = null;

                        EditorApplication.SetStatusCompiling(false);
                        EditorApplication.ReloadAssemblies();
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Builds the executable and packages the game.
        /// </summary>
        public static void Build()
        {
            PlatformType activePlatform = ActivePlatform;
            PlatformInfo platformInfo   = ActivePlatformInfo;

            string srcRoot  = GetBuildFolder(BuildFolder.SourceRoot, activePlatform);
            string destRoot = GetBuildFolder(BuildFolder.DestinationRoot, activePlatform);

            // Prepare clean destination folder
            if (Directory.Exists(destRoot))
            {
                Directory.Delete(destRoot, true);
            }

            Directory.CreateDirectory(destRoot);

            // Compile game assembly
            string bansheeAssemblyFolder;

            if (platformInfo.Debug)
            {
                bansheeAssemblyFolder = GetBuildFolder(BuildFolder.BansheeDebugAssemblies, activePlatform);
            }
            else
            {
                bansheeAssemblyFolder = GetBuildFolder(BuildFolder.BansheeReleaseAssemblies, activePlatform);
            }

            string srcBansheeAssemblyFolder  = Path.Combine(srcRoot, bansheeAssemblyFolder);
            string destBansheeAssemblyFolder = Path.Combine(destRoot, bansheeAssemblyFolder);

            Directory.CreateDirectory(destBansheeAssemblyFolder);
            CompilerInstance ci = ScriptCompiler.CompileAsync(ScriptAssemblyType.Game, ActivePlatform, platformInfo.Debug, destBansheeAssemblyFolder);

            // Copy engine assembly
            {
                string srcFile  = Path.Combine(srcBansheeAssemblyFolder, EditorApplication.EngineAssemblyName);
                string destFile = Path.Combine(destBansheeAssemblyFolder, EditorApplication.EngineAssemblyName);

                File.Copy(srcFile, destFile);
            }

            // Copy builtin data
            string dataFolder = GetBuildFolder(BuildFolder.Data, activePlatform);
            string srcData    = Path.Combine(srcRoot, dataFolder);
            string destData   = Path.Combine(destRoot, dataFolder);

            DirectoryEx.Copy(srcData, destData);

            // Copy native binaries
            string binaryFolder = GetBuildFolder(BuildFolder.NativeBinaries, activePlatform);
            string srcBin       = Path.Combine(srcRoot, binaryFolder);
            string destBin      = destRoot;

            string[] nativeBinaries = GetNativeBinaries(activePlatform);
            foreach (var entry in nativeBinaries)
            {
                string srcFile  = Path.Combine(srcBin, entry);
                string destFile = Path.Combine(destBin, entry);

                File.Copy(srcFile, destFile);
            }

            // Copy .NET framework assemblies
            string frameworkAssemblyFolder     = GetBuildFolder(BuildFolder.FrameworkAssemblies, activePlatform);
            string srcFrameworkAssemblyFolder  = Path.Combine(srcRoot, frameworkAssemblyFolder);
            string destFrameworkAssemblyFolder = Path.Combine(destRoot, frameworkAssemblyFolder);

            Directory.CreateDirectory(destFrameworkAssemblyFolder);

            string[] frameworkAssemblies = GetFrameworkAssemblies(activePlatform);
            foreach (var entry in frameworkAssemblies)
            {
                string srcFile  = Path.Combine(srcFrameworkAssemblyFolder, entry + ".dll");
                string destFile = Path.Combine(destFrameworkAssemblyFolder, entry + ".dll");

                File.Copy(srcFile, destFile);
            }

            // Copy Mono
            string monoFolder     = GetBuildFolder(BuildFolder.Mono, activePlatform);
            string srcMonoFolder  = Path.Combine(srcRoot, monoFolder);
            string destMonoFolder = Path.Combine(destRoot, monoFolder);

            DirectoryEx.Copy(srcMonoFolder, destMonoFolder);

            string srcExecFile  = GetMainExecutable(activePlatform);
            string destExecFile = Path.Combine(destBin, Path.GetFileName(srcExecFile));

            File.Copy(srcExecFile, destExecFile);

            InjectIcons(destExecFile, platformInfo);
            PackageResources(destRoot, platformInfo);
            CreateStartupSettings(destRoot, platformInfo);

            // Wait until compile finishes
            while (!ci.IsDone)
            {
                Thread.Sleep(200);
            }

            ci.Dispose();
        }