using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using UnityEditor; using UnityEditor.Build.Reporting; using UnityEngine; using static UnityEngine.GraphicsBuffer; class UploadToAllPlatforms { static List allGameScenes = new List() { "Assets/AllScenes/MainScene.unity", "Assets/AllScenes/Level1.unity", "Assets/AllScenes/Level2.unity" }; static string primaryOutputDirectory = @"E:\UnityBUilds\GameName\"; static Dictionary allPlatforms = new Dictionary() { }; class Cmd { internal string Path = null; internal string Arguments = null; } class Platform { internal BuildTarget target = BuildTarget.StandaloneWindows64; internal BuildOptions options = BuildOptions.CompressWithLz4HC; // Additional Options: https://docs.unity3d.com/ScriptReference/BuildOptions.html internal List scenes = allGameScenes; // Adopt your predefined list of scenes or add/remove scenes if necessary internal string output = null; internal List onSuccessCommandLineActions = new List(); internal List platformSpecificObjects = new List(); } static void ProcessAllPlatforms() { #region SynthesisVR - All Builds var synthesisVRcmd = @"""D:\Tools\SynthesisProducer\SynthesisVR - Producer Content Manager.exe"""; var synthesisVRlogin = "yourdevaccount"; var synthesisVRpassword = "yourdevaccount_password"; var synthesisVRgameid = "0000"; var synthesisVRgameObjects = new List() { GameObject.Find("SynthesisRootObject") }; #region PCVR Build for SynthesisVR var svr_PCVR = new Platform(); svr_PCVR.platformSpecificObjects = synthesisVRgameObjects; // Specify the local folder where the final platform build will be stored: svr_PCVR.output = primaryOutputDirectory + @"SynthesisVR\PCVR\GameName.exe"; // Each platform provides it's own set of upload tools. svr_PCVR.onSuccessCommandLineActions.Add(new Cmd { Path = synthesisVRcmd, Arguments = $"-autologin -autoupload -user={synthesisVRlogin} -pass={synthesisVRpassword} -gameid={synthesisVRgameid} -type=pcvr -basepath=\"" + Path.GetDirectoryName(svr_PCVR.output) + "\" -exe=\"" + Path.GetFileName(svr_PCVR.output) + "\"" }); allPlatforms.Add("SynthesisVR_PCVR", svr_PCVR); #endregion PCVR Build for SynthesisVR #region Quest Standalone Build for SynthesisVR var svr_Android_Quest = new Platform(); svr_Android_Quest.platformSpecificObjects = synthesisVRgameObjects; svr_Android_Quest.output = primaryOutputDirectory + @"SynthesisVR\Quest\GameName.apk"; svr_Android_Quest.target = BuildTarget.Android; svr_Android_Quest.onSuccessCommandLineActions.Add(new Cmd { Path = synthesisVRcmd, Arguments = $"-autologin -autoupload -user={synthesisVRlogin} -pass={synthesisVRpassword} -gameid={synthesisVRgameid} -type=quest -basepath=\"" + svr_Android_Quest.output + "\"" }); allPlatforms.Add("SynthesisVR_Quest", svr_Android_Quest); #endregion Quest Standalone Build for SynthesisVR #region Pico Standalone Build for SynthesisVR var svr_Android_Pico = new Platform(); svr_Android_Pico.platformSpecificObjects = synthesisVRgameObjects; svr_Android_Pico.output = primaryOutputDirectory + @"SynthesisVR\Pico\GameName.apk"; svr_Android_Pico.target = BuildTarget.Android; svr_Android_Pico.onSuccessCommandLineActions.Add(new Cmd { Path = synthesisVRcmd, Arguments = $"-autologin -autoupload -user={synthesisVRlogin} -pass={synthesisVRpassword} -gameid={synthesisVRgameid} -type=pico -basepath=\"" + svr_Android_Pico.output + "\"" }); allPlatforms.Add("SynthesisVR_Quest", svr_Android_Pico); #endregion Pico Standalone Build for SynthesisVR #region Focus 3 Standalone Build for SynthesisVR var svr_Android_Focus3 = new Platform(); svr_Android_Focus3.platformSpecificObjects = synthesisVRgameObjects; svr_Android_Focus3.output = primaryOutputDirectory + @"SynthesisVR\Focus3\GameName.apk"; svr_Android_Focus3.target = BuildTarget.Android; svr_Android_Focus3.onSuccessCommandLineActions.Add(new Cmd { Path = synthesisVRcmd, Arguments = $"-autologin -autoupload -user={synthesisVRlogin} -pass={synthesisVRpassword} -gameid={synthesisVRgameid} -type=htc -basepath=\"" + svr_Android_Focus3.output + "\"" }); allPlatforms.Add("SynthesisVR_Quest", svr_Android_Focus3); #endregion Focus 3 Standalone Build for SynthesisVR #endregion SynthesisVR - All Builds #region Process the builds var allCommandLineArguments = System.Environment.GetCommandLineArgs(); foreach (var platformName in allCommandLineArguments) { if (allPlatforms.ContainsKey(platformName)) { UnityEngine.Debug.Log($"Building Platform: {platformName}"); var platform = allPlatforms[platformName]; if (platform.output != null) { if (Directory.Exists(platform.output)) { DirectoryInfo di = new DirectoryInfo(platform.output); try { foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } catch (Exception ex) { UnityEngine.Debug.Log("ERROR: Cleaning up directory failed: " + ex.Message); } try { Directory.Delete(platform.output, true); } catch (Exception e) { UnityEngine.Debug.Log($"Unable to delete directory: {platform.output}"); } } // Enable my GameObjects + Disable GameObjects from other platforms foreach (var subPlatform in allPlatforms) { if (subPlatform.Key != platformName) { foreach (var obj in subPlatform.Value.platformSpecificObjects) { obj.SetActive(false); } } else { foreach (var obj in subPlatform.Value.platformSpecificObjects) { obj.SetActive(true); } } } // Perform the actual build: BuildReport report = BuildPipeline.BuildPlayer(platform.scenes.ToArray(), platform.output, platform.target, platform.options); BuildSummary summary = report.summary; if (summary.result == BuildResult.Succeeded) { UnityEngine.Debug.Log($"{platformName} Build succeeded: " + summary.totalSize + " bytes"); foreach(var runCmd in platform.onSuccessCommandLineActions) { if (File.Exists(runCmd.Path)) { Process cmd = new Process(); cmd.StartInfo.FileName = runCmd.Path; cmd.StartInfo.WorkingDirectory = Path.GetDirectoryName(runCmd.Path); cmd.StartInfo.Arguments = runCmd.Arguments ?? ""; cmd.Start(); cmd.WaitForExit(); } } } else if (summary.result == BuildResult.Failed) { UnityEngine.Debug.LogError($"{platformName} Build failed"); } } } } #endregion Process the builds } }