static void Init() { BundlePreviewWindow bundlePreviewWindow = GetWindowWithRect <BundlePreviewWindow>(new Rect(0, 0, 600, 400)); bundlePreviewWindow.Show(); currentDeviceAndAppStatus = DeviceAndAppStatus.UNKNOWN; }
//Build LoaderAPK public static void BuildandRunLoaderAPK(string loaderAPKPackageName) { loaderPackageName = loaderAPKPackageName; //Get path to this script string[] allPaths = Directory.GetFiles(Application.dataPath, "BundlePreviewManager.cs", SearchOption.AllDirectories); if (allPaths.Length > 1) { Debug.Log("Multiple BundlePreviewManager Scripts found, please check your SDK import."); return; } string pathToManager = allPaths[0]; //Get apk build path string finalAPKBuildDirectory = Path.Combine(Directory.GetParent(Application.dataPath).FullName, local_LoaderAPKPathRelative).Replace("/", "\\"); if (!Directory.Exists(finalAPKBuildDirectory)) { Directory.CreateDirectory(finalAPKBuildDirectory); Debug.Log("APK build directory not found, creating new directory at: " + finalAPKBuildDirectory); } string finalAPKBuildPath = Path.Combine(finalAPKBuildDirectory, loaderAPKFileName); //Get loader scene path loaderScenePathAbsolute = Path.Combine(Directory.GetParent(Directory.GetParent(pathToManager).FullName).FullName, loaderScenePathRelative).Replace("\\", "/"); Debug.Log("Loader Scene Path: " + loaderScenePathAbsolute); if (!File.Exists(loaderScenePathAbsolute)) { Debug.Log("Loader Scene Not Found, please check SDK import."); return; } Debug.Log("Loader Scene Found, start Building Loader APK."); BackupAndChangePlayerSettings(); #if UNITY_2018_1_OR_NEWER BuildReport report = BuildPipeline.BuildPlayer(new string[] { loaderScenePathAbsolute }, finalAPKBuildPath, BuildTarget.Android, BuildOptions.Development | BuildOptions.AutoRunPlayer); if (report.summary.result == BuildResult.Succeeded) { Debug.Log("Loader APK build successful, begin auto run on target device."); } else if (report.summary.result == BuildResult.Failed) { Debug.Log("Loader APK build failed. Error: " + report); } #else string error = BuildPipeline.BuildPlayer(new string[] { loaderScenePathAbsolute }, finalAPKBuildPath, BuildTarget.Android, BuildOptions.Development | BuildOptions.AutoRunPlayer); if (string.IsNullOrEmpty(error)) { Debug.Log("Loader APK build successful, begin auto run on target device."); } else { Debug.Log("Loader APK build failed. Error: " + error); } #endif RestorePlayerSettings(); BundlePreviewWindow.APKBuildFinished(); }