Search Unity

Progress Bar not Updating When Building

Discussion in 'Immediate Mode GUI (IMGUI)' started by QFSW, Sep 1, 2015.

  1. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,906
    Hi all, Im making an editor extension to automate my build workflow
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4.  
    5. class AutoBuild : EditorWindow {
    6.     bool Mac=false;
    7.     bool Windows=false;
    8.     bool Linux=false;
    9.     bool Android=false;
    10.     bool Building=false;
    11.     bool Revert=false;
    12.     bool Batch=false;
    13.     bool MacBatch=false;
    14.     bool WindowsBatch=false;
    15.     bool LinuxBatch=false;
    16.     bool AndroidBatch=false;
    17.     bool UniBatch=false;
    18.  
    19.     int Jobs=0;
    20.  
    21.     float CurrentJobNumber=0;
    22.     float Progress=0f;
    23.  
    24.     string[] Scenes=new string[1];
    25.     string BuildName;
    26.     string BuildPath;
    27.     string SceneName;
    28.     string MacBatchPath;
    29.     string WindowsBatchPath;
    30.     string LinuxBatchPath;
    31.     string AndroidBatchPath;
    32.     string UniversalBatchPath;
    33.     string CurrentJob;
    34.     string JobLabel;
    35.  
    36.     BuildTarget Target= EditorUserBuildSettings.activeBuildTarget;
    37.     [MenuItem ("Window/Autoumated Builds")]
    38.    
    39.     public static void ShowWindow () {
    40.         EditorWindow.GetWindow(typeof(AutoBuild));
    41.     }
    42.  
    43.     void OnEnable()
    44.     {
    45.         Mac=EditorPrefs.GetBool("Mac",false);
    46.         Windows=EditorPrefs.GetBool("Windows",false);
    47.         Linux=EditorPrefs.GetBool("Linux",false);
    48.         Android=EditorPrefs.GetBool("Android",false);
    49.         Revert=EditorPrefs.GetBool("Revert",false);
    50.         Batch=EditorPrefs.GetBool("Batch",false);
    51.         MacBatch=EditorPrefs.GetBool("MacBatch",false);
    52.         WindowsBatch=EditorPrefs.GetBool("WindowsBatch",false);
    53.         LinuxBatch=EditorPrefs.GetBool("LinuxBatch",false);
    54.         AndroidBatch=EditorPrefs.GetBool("AndroidBatch",false);
    55.         UniBatch=EditorPrefs.GetBool("UniBatch",false);
    56.         BuildName=EditorPrefs.GetString("BuildName","");
    57.         BuildPath=EditorPrefs.GetString("BuildPath","");
    58.         SceneName=EditorPrefs.GetString("SceneName","");
    59.         MacBatchPath=EditorPrefs.GetString("MacBatchPath","");
    60.         WindowsBatchPath=EditorPrefs.GetString("WindowsBatchPath","");
    61.         LinuxBatchPath=EditorPrefs.GetString("LinuxBatchPath","");
    62.         AndroidBatchPath=EditorPrefs.GetString("AndroidBatchPath","");
    63.         UniversalBatchPath=EditorPrefs.GetString("UniversalBatchPath","");
    64.  
    65.     }
    66.  
    67.     void OnDisable()
    68.     {
    69.         EditorPrefs.SetBool("Mac",Mac);
    70.         EditorPrefs.SetBool("Windows",Windows);
    71.         EditorPrefs.SetBool("Linux",Linux);
    72.         EditorPrefs.SetBool("Android",Android);
    73.         EditorPrefs.SetBool("Revert",Revert);
    74.         EditorPrefs.SetBool("Batch",Batch);
    75.         EditorPrefs.SetBool("MacBatch",MacBatch);
    76.         EditorPrefs.SetBool("WindowsBatch",WindowsBatch);
    77.         EditorPrefs.SetBool("LinuxBatch",LinuxBatch);
    78.         EditorPrefs.SetBool("AndroidBatch",AndroidBatch);
    79.         EditorPrefs.SetBool("UniBatch",UniBatch);
    80.         EditorPrefs.SetString("BuildName",BuildName);
    81.         EditorPrefs.SetString("BuildPath",BuildPath);
    82.         EditorPrefs.SetString("SceneName",SceneName);
    83.         EditorPrefs.SetString("MacBatchPath",MacBatchPath);
    84.         EditorPrefs.SetString("WindowsBatchPath",WindowsBatchPath);
    85.         EditorPrefs.SetString("LinuxBatchPath",LinuxBatchPath);
    86.         EditorPrefs.SetString("AndroidBatchPath",AndroidBatchPath);
    87.         EditorPrefs.SetString("UniversalBatchPath",UniversalBatchPath);
    88.     }
    89.  
    90.     void OnGUI()
    91.     {
    92.         GUILayout.Label ("Build Information", EditorStyles.boldLabel);
    93.         BuildName = EditorGUILayout.TextField ("Build Name", BuildName);
    94.         BuildPath = EditorGUILayout.TextField ("Build Directory Path", BuildPath);
    95.         SceneName = EditorGUILayout.TextField ("Scene Name", SceneName);
    96.         GUILayout.Label ("Build Targets", EditorStyles.boldLabel);
    97.         Mac = EditorGUILayout.Toggle ("Mac", Mac);
    98.         Windows = EditorGUILayout.Toggle ("Windows", Windows);
    99.         Linux = EditorGUILayout.Toggle ("Linux", Linux);
    100.         Android = EditorGUILayout.Toggle ("Android", Android);
    101.         GUILayout.Label ("Post Processing", EditorStyles.boldLabel);
    102.         Batch=EditorGUILayout.BeginToggleGroup("Batch/Shell Script",Batch);
    103.         MacBatch=EditorGUILayout.BeginToggleGroup("Mac",MacBatch);
    104.         MacBatchPath = EditorGUILayout.TextField ("File Path+Name", MacBatchPath);
    105.         EditorGUILayout.EndToggleGroup();
    106.         WindowsBatch=EditorGUILayout.BeginToggleGroup("Windows",WindowsBatch);
    107.         WindowsBatchPath = EditorGUILayout.TextField ("File Path+Name", WindowsBatchPath);
    108.         EditorGUILayout.EndToggleGroup();
    109.         LinuxBatch=EditorGUILayout.BeginToggleGroup("Linux",LinuxBatch);
    110.         LinuxBatchPath = EditorGUILayout.TextField ("File Path+Name", LinuxBatchPath);
    111.         EditorGUILayout.EndToggleGroup();
    112.         AndroidBatch=EditorGUILayout.BeginToggleGroup("Android",AndroidBatch);
    113.         AndroidBatchPath = EditorGUILayout.TextField ("File Path+Name", AndroidBatchPath);
    114.         EditorGUILayout.EndToggleGroup();
    115.         UniBatch=EditorGUILayout.BeginToggleGroup("Universal",UniBatch);
    116.         UniversalBatchPath = EditorGUILayout.TextField ("File Path+Name", UniversalBatchPath);
    117.         EditorGUILayout.EndToggleGroup();
    118.         EditorGUILayout.EndToggleGroup();
    119.         GUILayout.Label ("Other Settings", EditorStyles.boldLabel);
    120.         Revert=EditorGUILayout.Toggle("Revert Platform",Revert);
    121.  
    122.         if(GUILayout.Button("Build"))
    123.         {
    124.             if(Building==false)
    125.             {
    126.                 Building=true;
    127.                 Scenes[0]=SceneName;
    128.                 PerformBuilds();
    129.             }
    130.         }
    131.         if(Building)
    132.         {
    133.             Progress=(CurrentJobNumber-1)/Jobs;
    134.             if(CurrentJobNumber<=Jobs){JobLabel="Job "+CurrentJobNumber.ToString()+"/"+Jobs.ToString()+": "+CurrentJob;}
    135.             EditorGUI.ProgressBar(new Rect(new Vector2 (5,Screen.height-45),new Vector2 (Screen.width-10,20)),Progress,JobLabel);
    136.         }
    137.     }
    138.     public void PerformBuilds()
    139.     {
    140.         EditorApplication.update+=Repaint;
    141.  
    142.         Target= EditorUserBuildSettings.activeBuildTarget;
    143.  
    144.         Jobs=0;
    145.         CurrentJobNumber=0;
    146.         if(Mac){Jobs++;}
    147.         if(Windows){Jobs++;}
    148.         if(Linux){Jobs++;}
    149.         if(Android){Jobs++;}
    150.         if(Batch)
    151.         {
    152.             if(MacBatch&&Mac){Jobs++;}
    153.             if(WindowsBatch&&Windows){Jobs++;}
    154.             if(LinuxBatch&&Linux){Jobs++;}
    155.             if(AndroidBatch&&Android){Jobs++;}
    156.             if(UniBatch){Jobs++;}
    157.         }
    158.  
    159.  
    160.         if(Mac)
    161.         {
    162.             CurrentJobNumber++;
    163.             CurrentJob="Building Mac Standalone Player";
    164.             BuildPipeline.BuildPlayer(Scenes, BuildPath+"/"+BuildName,BuildTarget.StandaloneOSXIntel64, BuildOptions.None);
    165.             if(Batch&&MacBatch)
    166.             {
    167.                 CurrentJobNumber++;
    168.                 System.Diagnostics.Process.Start(MacBatchPath).WaitForExit();
    169.             }
    170.         }
    171.         if(Windows)
    172.         {
    173.             CurrentJobNumber++;
    174.             CurrentJob="Building Windows Standalone Player";
    175.             BuildPipeline.BuildPlayer(Scenes, BuildPath+"/"+BuildName+".exe",BuildTarget.StandaloneWindows, BuildOptions.None);
    176.             if(Batch&&WindowsBatch)
    177.             {
    178.                 CurrentJobNumber++;
    179.                 System.Diagnostics.Process.Start(WindowsBatchPath).WaitForExit();
    180.             }
    181.         }
    182.         if(Linux)
    183.         {
    184.             CurrentJobNumber++;
    185.             CurrentJob="Building Linux Standalone Player";
    186.             BuildPipeline.BuildPlayer(Scenes, BuildPath+"/"+BuildName+".x86",BuildTarget.StandaloneLinux, BuildOptions.None);
    187.             if(Batch&&WindowsBatch)
    188.             {
    189.                 CurrentJobNumber++;
    190.                 System.Diagnostics.Process.Start(WindowsBatchPath).WaitForExit();
    191.             }
    192.         }
    193.         if(Android)
    194.         {
    195.             CurrentJobNumber++;
    196.             CurrentJob="Building Android APK";
    197.             BuildPipeline.BuildPlayer(Scenes, BuildPath+"/"+BuildName+".apk",BuildTarget.Android, BuildOptions.None);
    198.             if(Batch&&LinuxBatch)
    199.             {
    200.                 CurrentJobNumber++;
    201.                 System.Diagnostics.Process.Start(AndroidBatchPath);
    202.             }
    203.         }
    204.         if(Batch&&UniBatch)
    205.         {
    206.             CurrentJobNumber++;
    207.             System.Diagnostics.Process.Start(UniversalBatchPath);
    208.         }
    209.         if(Revert)
    210.         {
    211.             if (EditorUserBuildSettings.activeBuildTarget!=Target)
    212.             {
    213.                 CurrentJobNumber++;
    214.                 CurrentJob="Reverting to Original Platform";
    215.                 EditorUserBuildSettings.SwitchActiveBuildTarget(Target);
    216.             }
    217.         }
    218.         EditorApplication.update-=Repaint;
    219.  
    220.         Building=false;
    221.     }
    222. }
    223.  
    When I have batch scripts enabled it should update that its doing that job when it comes to it, but it skips it, eg it goes straight from Mac to Windows builds, skipping out the Mac Batch scripts
    It function fine, but it just doesnt update and show its doing this job, does anyone know how to fix this?