Ejemplo n.º 1
0
        public static void Build()
        {
            if (UnityEditor.BuildPipeline.isBuildingPlayer)
            {
                return;
            }
            settings = BuildPipelineIOSSettings.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;
            }
            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...");
            }
        }
Ejemplo n.º 2
0
 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.createNewFolder = EditorGUILayout.Toggle("Create new folder", settings.createNewFolder);
         settings.setURLSchemes   = EditorGUILayout.Toggle("Set URLSchemes", settings.setURLSchemes);
         if (settings.setURLSchemes)
         {
             if (settings.urlSchemes == null)
             {
                 settings.urlSchemes = new string[0];
             }
             urlSchemeList.Clear();
             urlSchemeList.AddRange(settings.urlSchemes);
             listMain.DoLayoutList();
         }
         settings.buildOptions = (BuildOptions)EditorGUILayout.EnumFlagsField("Build options", settings.buildOptions);
         if (changeScope.changed || isDirty)
         {
             isDirty = false;
             if (settings.setURLSchemes)
             {
                 settings.urlSchemes = urlSchemeList.ToArray();
             }
             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();
         }
     }
 }