public static void Build()
        {
            if (UnityEditor.BuildPipeline.isBuildingPlayer)
            {
                return;
            }
            settings = AndroidBuildPipelineSettings.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;
            }
            if (settings.incrementBundle)
            {
                int bundleVersion = PlayerSettings.Android.bundleVersionCode;
                bundleVersion++;
                PlayerSettings.Android.bundleVersionCode = bundleVersion;
            }
            if (settings.useKeystore)
            {
                PlayerSettings.Android.keystoreName = settings.keystoreName;
                PlayerSettings.Android.keystorePass = settings.keystorePass;
                PlayerSettings.Android.keyaliasName = settings.keyaliasName;
                PlayerSettings.Android.keyaliasPass = settings.keyaliasPass;
            }
            string       fileName  = settings.GetFileName();
            string       buildPath = Path.Combine(path, fileName);
            BuildReport  report    = UnityEditor.BuildPipeline.BuildPlayer(scenes.ToArray(), buildPath, BuildTarget.Android, 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.");
                Application.OpenURL(path);
            }
            if (summary.result == BuildResult.Failed)
            {
                Debug.LogError($"Build failed...");
            }
        }
 private void OnGUI()
 {
     GUI.enabled = !UnityEditor.BuildPipeline.isBuildingPlayer;
     EditorGUILayout.LabelField("File 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.GetFileName(), EditorStyles.helpBox);
     using (var changeScope = new EditorGUI.ChangeCheckScope())
     {
         settings.dateTimeFormat  = EditorGUILayout.TextField("Date time format", settings.dateTimeFormat);
         settings.incrementBundle = EditorGUILayout.Toggle("Increase Bundle Version", settings.incrementBundle);
         settings.useKeystore     = EditorGUILayout.Toggle("Use Keystore", settings.useKeystore);
         settings.buildOptions    = (BuildOptions)EditorGUILayout.EnumFlagsField("Build options", settings.buildOptions);
         if (changeScope.changed)
         {
             settings.Save();
         }
     }
     if (settings.useKeystore)
     {
         using (var verticalScope = new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
         {
             EditorGUILayout.HelpBox(HELPBOX_USE_KEYSTORE_INFO, MessageType.Warning, true);
             using (var horizontalScope = new EditorGUILayout.HorizontalScope())
             {
                 EditorGUILayout.LabelField("Keystore Name", settings.keystoreName);
                 if (GUILayout.Button("Change...", GUILayout.Width(96.0f)))
                 {
                     var path = EditorUtility.OpenFilePanelWithFilters("Choose Location of Build Game", string.IsNullOrEmpty(settings.keystoreName) ? string.Empty : settings.keystoreName, KEYSTORE_EXTENSIONS);
                     if (string.IsNullOrEmpty(path))
                     {
                         return;
                     }
                     settings.keystoreName = path;
                     settings.Save();
                 }
             }
             using (var changeScope = new EditorGUI.ChangeCheckScope())
             {
                 settings.keystorePass = EditorGUILayout.PasswordField("Keystore Password", settings.keystorePass);
                 settings.keyaliasName = EditorGUILayout.TextField("Keyalias Name", settings.keyaliasName);
                 settings.keyaliasPass = EditorGUILayout.PasswordField("Keyalias Password", settings.keyaliasPass);
                 if (changeScope.changed)
                 {
                     settings.Save();
                 }
             }
             GUILayout.Space(16.0f);
             using (var horizontalScope = new EditorGUILayout.HorizontalScope())
             {
                 GUILayout.FlexibleSpace();
                 Color cacheColor = GUI.color;
                 GUI.color = Color.red;
                 if (GUILayout.Button("Clear Keystore Settings", GUILayout.MaxWidth(256.0f)))
                 {
                     settings.keystoreName = string.Empty;
                     settings.keystorePass = string.Empty;
                     settings.keyaliasName = string.Empty;
                     settings.keyaliasPass = string.Empty;
                     settings.Save();
                 }
                 GUI.color = cacheColor;
                 GUILayout.FlexibleSpace();
             }
             GUILayout.Space(16.0f);
         }
     }
     using (var verticalScope = new EditorGUILayout.VerticalScope())
     {
         using (var horizontalScope = new EditorGUILayout.HorizontalScope())
         {
             EditorGUILayout.LabelField("Build 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();
         }
     }
 }