Created
December 5, 2021 11:47
-
-
Save tallestorange/63356aa591fcc80e4e11871b021e6634 to your computer and use it in GitHub Desktop.
HoloLens2アプリ自動ビルドスクリプト(MRTK使用)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using Microsoft.MixedReality.Toolkit.Build.Editor; | |
| using Microsoft.MixedReality.Toolkit.Utilities.Editor; | |
| using System.IO; | |
| using System.Threading; | |
| using System.Threading.Tasks; | |
| using System.Xml.Linq; | |
| using UnityEditor; | |
| using UnityEngine; | |
| public class AutoBuild | |
| { | |
| [MenuItem("ビルド/appxビルド")] | |
| private static void BuildMenu() | |
| { | |
| if (EditorUserBuildSettings.selectedBuildTargetGroup == BuildTargetGroup.WSA) | |
| { | |
| BuildSequence(); | |
| } | |
| else | |
| { | |
| EditorUtility.DisplayDialog("Error", "PlatformをUWPに設定してください", "OK"); | |
| } | |
| } | |
| private static async void BuildSequence() | |
| { | |
| EditorUserBuildSettings.wsaArchitecture = "ARM"; | |
| EditorUserBuildSettings.wsaSubtarget = WSASubtarget.HoloLens; | |
| var buildInfo = new UwpBuildInfo | |
| { | |
| RebuildAppx = false, | |
| BuildAppx = false, | |
| Configuration = "release", | |
| BuildPlatform = "ARM", | |
| PlatformToolset = UwpBuildDeployPreferences.PlatformToolset, | |
| OutputDirectory = BuildDeployPreferences.BuildDirectory, | |
| AutoIncrement = false, | |
| Multicore = true, | |
| ResearchModeCapabilityEnabled = false | |
| }; | |
| var r1 = await BuildProject(buildInfo); | |
| if (!r1) | |
| { | |
| Debug.LogError("BuildProject error"); | |
| return; | |
| } | |
| UwpAppxBuildTools.AddCapabilities(buildInfo); | |
| UwpAppxBuildTools.UpdateAssemblyCSharpProject(buildInfo); | |
| AddCapability(buildInfo); | |
| var r2 = await BuildAppx(buildInfo); | |
| if (!r2) | |
| { | |
| Debug.LogError("BuildAppx error"); | |
| return; | |
| } | |
| } | |
| public static void Build() | |
| { | |
| BuildSequence(); | |
| var path = GetAppxFilePath(); | |
| var appxFileName = GetAppxFileName(); | |
| var fullPath = Path.GetFullPath(Path.Combine(path, appxFileName)); | |
| var outputPath = Path.Combine("C:/Users/Yuhel", appxFileName); | |
| File.Copy(fullPath, outputPath); | |
| Debug.LogFormat("File is copied to {0}", outputPath); | |
| } | |
| private static async Task<bool> BuildProject(UwpBuildInfo buildInfo) | |
| { | |
| var appxCancellationTokenSource = new CancellationTokenSource(); | |
| var result = await UwpPlayerBuildTools.BuildPlayer(buildInfo, appxCancellationTokenSource.Token); | |
| appxCancellationTokenSource.Dispose(); | |
| return result; | |
| } | |
| private static async Task<bool> BuildAppx(UwpBuildInfo buildInfo) | |
| { | |
| EditorAssemblyReloadManager.LockReloadAssemblies = true; | |
| var appxCancellationTokenSource = new CancellationTokenSource(); | |
| var result = await UwpAppxBuildTools.BuildAppxAsync(buildInfo, appxCancellationTokenSource.Token); | |
| appxCancellationTokenSource.Dispose(); | |
| EditorAssemblyReloadManager.LockReloadAssemblies = false; | |
| return result; | |
| } | |
| private static void AddCapability(UwpBuildInfo buildInfo) | |
| { | |
| var manifestFilePath = GetManifestPath(buildInfo); | |
| var rootNode = XElement.Load(manifestFilePath); | |
| UwpAppxBuildTools.AddCapability(rootNode, rootNode.GetDefaultNamespace() + "DeviceCapability", "documentsLibrary"); | |
| rootNode.Save(manifestFilePath); | |
| } | |
| private static string GetManifestPath(IBuildInfo buildInfo) | |
| { | |
| var fullPathOutputDirectory = Path.GetFullPath(buildInfo.OutputDirectory); | |
| string[] manifests = Directory.GetFiles(fullPathOutputDirectory, "Package.appxmanifest", SearchOption.AllDirectories); | |
| if (manifests.Length == 0 || manifests.Length > 1) | |
| { | |
| return null; | |
| } | |
| return manifests[0]; | |
| } | |
| private static string GetAppxFileName() | |
| { | |
| return string.Format("{0}_{1}_{2}.appx", PlayerSettings.productName, PlayerSettings.WSA.packageVersion, "ARM"); | |
| } | |
| private static string GetAppxFilePath() | |
| { | |
| var path = Path.Combine( | |
| BuildDeployPreferences.BuildDirectory, | |
| "AppPackages", | |
| PlayerSettings.productName, | |
| string.Format("{0}_{1}_{2}_{3}", PlayerSettings.productName, PlayerSettings.WSA.packageVersion, "ARM", "Test") | |
| ); | |
| return path; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "C:\Program Files\Unity\Hub\Editor\2020.3.24f1\Editor\Unity.exe" -batchmode -quit -logFile hoge.log -executeMethod AutoBuild.Build -buildTarget WindowsStoreApps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment