Пример #1
0
        public static void BuildPlayer(bool run = false)
        {
            //Just in case, we save the settings
            BuildSettings.Save();

            string path = EditorUtility.SaveFolderPanel("Choose Location of Built Game", EditorUserBuildSettings.GetBuildLocation(BuildTarget.WebGL), "");

            if (Directory.Exists(path))
            {
                ProgressHelper progress = new ProgressHelper();
                progress.Reset(5);


                //Set Template
                string lastUsedTemplate = TemplateManager.SetChromeTemplate("PROJECT:ChromeApp");
                //Define symbols
                Builder.SetDefineSymbol(true);
                //Create subfolder
                path = Builder.CreateSubFolder(path);

                progress.SetCleanupCallback(() => {
                    //Clean up
                    //Reset Webgl template
                    TemplateManager.SetChromeTemplate(lastUsedTemplate);
                    //Define symbols
                    Builder.SetDefineSymbol(false);
                });
                //BUILD
                if (!Builder.BuildPlayer(path))
                {
                    progress.Done();
                    return;
                }
                //Process template
                progress.Step("Building Player - Chrome App", "Postprocessing Template Variables");
                TemplateManager.ProcessTemplateFiles(path);
                //Creatig Icons
                progress.Step("Building Player - Chrome App", "Creating icons");
                Icons.CreateIcons(path);
                //Creating Manifest
                progress.Step("Building Player - Chrome App", "Creating manifest");
                Manifest.CreateManifestFile(path);
                //Packing Extention
                progress.Step("Building Player - Chrome App", "Packing Extension into .crx file");
                if (BuildSettings.Get.packExtension)
                {
                    if (!ChromeHelper.PackExtension(path))
                    {
                        Debug.LogWarning("Chrome app was not packed into a .crx file.");
                    }
                }
                //launch player or reveal in explorer
                progress.Step("Building Player - Chrome App", "Launching");
                if (run)
                {
                    if (File.Exists(path + ".crx"))
                    {
                        CrxHeader header = new CrxHeader(path + ".crx");
                        Manifest.AddKeyToManifest(Path.Combine(path, "manifest.json"), header.PublicKey);
                    }
                    ChromeHelper.LoadAndRunExtension(path);
                }
                else
                {
                    EditorUtility.RevealInFinder(path);
                }
                //Clear progress and cleanup
                progress.Done();
            }
        }
Пример #2
0
 private void OnDisable()
 {
     BuildSettings.Save();
 }