private void OnGUI()
 {
     GUI.enabled = !UnityEditor.BuildPipeline.isBuildingPlayer;
     EditorGUILayout.LabelField("Folder name formatting", EditorStyles.boldLabel);
     using (var changeScope = new EditorGUI.ChangeCheckScope())
     {
         settings.nameFormat = EditorGUILayout.TextField(settings.nameFormat);
         if (changeScope.changed)
         {
             settings.Save();
         }
     }
     EditorGUILayout.HelpBox(HELPBOX_NAME_FORMATTING_INFO, MessageType.Info, true);
     EditorGUILayout.LabelField("Formatted name", settings.GetFolderName(), EditorStyles.helpBox);
     using (var changeScope = new EditorGUI.ChangeCheckScope())
     {
         settings.dateTimeFormat       = EditorGUILayout.TextField("Date time format", settings.dateTimeFormat);
         settings.stripMobileWarning   = EditorGUILayout.Toggle("Strip mobile warning", settings.stripMobileWarning);
         settings.fixMacOSVersionRegex = EditorGUILayout.Toggle("Fix Mac OS Version Regex", settings.fixMacOSVersionRegex);
         settings.createNewFolder      = EditorGUILayout.Toggle("Create new folder", settings.createNewFolder);
         settings.linkerTarget         = (WebGLLinkerTarget)EditorGUILayout.EnumPopup("Linker target", settings.linkerTarget);
         settings.memorySize           = EditorGUILayout.IntField("Memory size", settings.memorySize);
         settings.compressionFormat    = (WebGLCompressionFormat)EditorGUILayout.EnumPopup("Compression", settings.compressionFormat);
         settings.wasmStreaming        = EditorGUILayout.Toggle("WASM Streaming", settings.wasmStreaming);
         settings.buildOptions         = (BuildOptions)EditorGUILayout.EnumFlagsField("Build options", settings.buildOptions);
         string templateName = PlayerSettings.WebGL.template.Substring(PlayerSettings.WebGL.template.IndexOf(':') + 1);
         EditorGUILayout.LabelField("Template", templateName, EditorStyles.helpBox);
         if (changeScope.changed)
         {
             settings.Save();
         }
     }
     using (var verticalScope = new EditorGUILayout.VerticalScope())
     {
         using (var horizontalScope = new EditorGUILayout.HorizontalScope())
         {
             EditorGUILayout.LabelField("Build location", string.IsNullOrWhiteSpace(settings.buildPath) ? "<No location>" : settings.buildPath);
             if (GUILayout.Button("Change...", GUILayout.Width(96.0f)))
             {
                 var path = OpenBuildSavePanel(settings.buildPath);
                 if (!string.IsNullOrEmpty(path))
                 {
                     settings.buildPath = path;
                 }
             }
         }
         using (var horizontalScope = new EditorGUILayout.HorizontalScope())
         {
             GUILayout.FlexibleSpace();
             bool cacheEnable = GUI.enabled;
             GUI.enabled = !string.IsNullOrWhiteSpace(settings.buildPath);
             if (GUILayout.Button("Open Build Location", GUILayout.MaxWidth(256.0f)))
             {
                 Application.OpenURL(settings.buildPath);
             }
             GUI.enabled = cacheEnable;
             GUILayout.FlexibleSpace();
         }
     }
 }
Beispiel #2
0
        public static void Build()
        {
            if (UnityEditor.BuildPipeline.isBuildingPlayer)
            {
                return;
            }
            settings = BuildPipelineWebGLSettings.Instance;
            string path;

            if (string.IsNullOrEmpty(settings.buildPath))
            {
                path = OpenBuildSavePanel(settings.buildPath);
            }
            else
            {
                path = settings.buildPath;
            }
            var scenes = new List <EditorBuildSettingsScene>(EditorBuildSettings.scenes);

            for (int i = 0; i < scenes.Count; i++)
            {
                if (!scenes[i].enabled)
                {
                    scenes.RemoveAt(i--);
                }
            }
            if (!(scenes.Count > 0))
            {
                return;
            }
            string buildPath;

            if (settings.createNewFolder)
            {
                buildPath = Path.Combine(path, settings.GetFolderName());
            }
            else
            {
                buildPath = path;
            }
            PlayerSettings.WebGL.linkerTarget      = settings.linkerTarget;
            PlayerSettings.WebGL.memorySize        = settings.memorySize;
            PlayerSettings.WebGL.compressionFormat = settings.compressionFormat;
            PlayerSettings.WebGL.wasmStreaming     = settings.wasmStreaming;
            BuildReport  report  = UnityEditor.BuildPipeline.BuildPlayer(scenes.ToArray(), buildPath, BuildTarget.WebGL, settings.buildOptions);
            BuildSummary summary = report.summary;

            if (summary.result == BuildResult.Succeeded)
            {
                Debug.Log($"Build succeeded at '{buildPath}' using {summary.totalTime.TotalSeconds.ToString("N2")} seconds with size of {summary.totalSize} bytes.");
#if UNITY_EDITOR_OSX
                Application.OpenURL("file:/" + buildPath);
#else
                Application.OpenURL(buildPath);
#endif
            }
            if (summary.result == BuildResult.Failed)
            {
                Debug.LogError($"Build failed...");
            }
        }