Advertisement
BlackDragonBE

Unity Auto Multiplatform Build Script

Sep 20th, 2015
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.04 KB | None | 0 0
  1. using UnityEditor;
  2. using System.Diagnostics;
  3. using System.IO;
  4.  
  5. /*
  6. This script will automatically make a Windows, Mac and Linux build in any folder you choose.
  7.  
  8.     Usage:
  9.     - Drop this script in an Editor folder
  10.     - Change paramaters depending on your game / preferences
  11.     - In Unity Editor: Build/Multi Build
  12.     - Builds will be made and zipped by 7zip if chosen to do so and 7zip is installed on the system
  13. */
  14.  
  15. public class MultiBuild
  16. {
  17.     [MenuItem("Build/Multi Build")]
  18.     public static void DoMultiBuild()
  19.     {
  20.         // Get filename.
  21.         string path = EditorUtility.SaveFolderPanel("Choose Builds Folder", "", "");
  22.  
  23.         //PARAMETERS START
  24.         string gameName = "Dyna Bros"; //Name of your game
  25.         string[] levels = new string[] { "Assets/Scenes/Title.unity", "Assets/Scenes/Game.unity" }; //Scenes in order of loading
  26.         bool zipFolders = true; //Use 7zip to compress the created folders
  27.         //PARAMETERS END
  28.  
  29.         // Build Win
  30.         BuildPipeline.BuildPlayer(levels, path + "/Win/" + gameName + ".exe", BuildTarget.StandaloneWindows, BuildOptions.None);
  31.  
  32.         // Build Mac
  33.         BuildPipeline.BuildPlayer(levels, path + "/Mac/" + gameName + ".app", BuildTarget.StandaloneOSXUniversal, BuildOptions.None);
  34.  
  35.         // Build Linux
  36.         BuildPipeline.BuildPlayer(levels, path + "/Linux/" + gameName + ".x86", BuildTarget.StandaloneLinuxUniversal, BuildOptions.None);
  37.  
  38.         // 7zip
  39.         if (zipFolders && File.Exists(@"C:\Program Files\7-Zip\7z.exe"))
  40.         {
  41.             ZipFolder(path + "/Win/", gameName + " Win.zip");
  42.             ZipFolder(path + "/Mac/", gameName + " Mac.zip");
  43.             ZipFolder(path + "/Linux/", gameName + " Linux.zip");
  44.         }
  45.  
  46.  
  47.     }
  48.  
  49.     static void ZipFolder(string folderPath, string zipName)
  50.     {
  51.         Process proc = new Process();
  52.         proc.StartInfo.FileName = @"C:\Program Files\7-Zip\7z.exe";
  53.         proc.StartInfo.Arguments = "a -tzip " + '"' + zipName + '"' + " " + '"' + folderPath + '"';
  54.         proc.Start();
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement