public void OnPreprocessBuild(BuildReport report)
    {
        buildStartTime = System.DateTime.Now;
        buildGuid      = System.Guid.NewGuid();

        if (!report.summary.outputPath.Contains("OVRGradleTempExport"))
        {
            OVRPlugin.SetDeveloperMode(OVRPlugin.Bool.True);
            OVRPlugin.AddCustomMetadata("build_type", "standard");
        }

        OVRPlugin.AddCustomMetadata("build_guid", buildGuid.ToString());
        OVRPlugin.AddCustomMetadata("target_platform", report.summary.platform.ToString());
        OVRPlugin.AddCustomMetadata("scripting_runtime_version", UnityEditor.PlayerSettings.scriptingRuntimeVersion.ToString());
        if (report.summary.platform == UnityEditor.BuildTarget.StandaloneWindows ||
            report.summary.platform == UnityEditor.BuildTarget.StandaloneWindows64)
        {
            OVRPlugin.AddCustomMetadata("target_oculus_platform", "rift");
        }
#if BUILDSESSION
        StreamWriter writer = new StreamWriter("build_session", false);
        UnityEngine.Debug.LogFormat("Build Session: {0}", buildGuid.ToString());
        writer.WriteLine(buildGuid.ToString());
        writer.Close();
#endif
    }
Exemple #2
0
 public void OnPreprocessBuild(BuildReport report)
 {
     OVRPlugin.AddCustomMetadata("target_platform", report.summary.platform.ToString());
     if (report.summary.platform == UnityEditor.BuildTarget.StandaloneWindows ||
         report.summary.platform == UnityEditor.BuildTarget.StandaloneWindows64)
     {
         OVRPlugin.AddCustomMetadata("target_oculus_platform", "rift");
     }
 }
Exemple #3
0
    static void OnDelayCall()
    {
        setPrefsForUtilities = PlayerPrefs.GetInt(prefName, 1) != 0;
        Menu.SetChecked(menuItemName, setPrefsForUtilities);

        if (!setPrefsForUtilities)
        {
            return;
        }

        OVRPlugin.AddCustomMetadata("build_target", EditorUserBuildSettings.activeBuildTarget.ToString());
        EnforceAndroidSettings();
    }
Exemple #4
0
    public void OnPreprocessBuild(BuildReport report)
    {
#if UNITY_ANDROID && !(USING_XR_SDK && UNITY_2019_3_OR_NEWER)
        // Generate error when Vulkan is selected as the perferred graphics API, which is not currently supported in Unity XR
        if (!PlayerSettings.GetUseDefaultGraphicsAPIs(BuildTarget.Android))
        {
            GraphicsDeviceType[] apis = PlayerSettings.GetGraphicsAPIs(BuildTarget.Android);
            if (apis.Length >= 1 && apis[0] == GraphicsDeviceType.Vulkan)
            {
                throw new BuildFailedException("The Vulkan Graphics API does not support XR in your configuration. To use Vulkan, you must use Unity 2019.3 or newer, and the XR Plugin Management.");
            }
        }
#endif

#if UNITY_ANDROID && USING_XR_SDK && !USING_COMPATIBLE_OCULUS_XR_PLUGIN_VERSION
        if (PlayerSettings.Android.targetArchitectures != AndroidArchitecture.ARM64)
        {
            throw new BuildFailedException("Your project is using an Oculus XR Plugin version with known issues. Please navigate to the Package Manager and upgrade the Oculus XR Plugin to the latest verified version. When performing the upgrade" +
                                           ", you must first \"Remove\" the Oculus XR Plugin package, and then \"Install\" the package at the verified version. Be sure to remove, then install, not just upgrade.");
        }
#endif

        buildStartTime = System.DateTime.Now;
        buildGuid      = System.Guid.NewGuid();

        if (!report.summary.outputPath.Contains("OVRGradleTempExport"))
        {
            OVRPlugin.SetDeveloperMode(OVRPlugin.Bool.True);
            OVRPlugin.AddCustomMetadata("build_type", "standard");
        }

        OVRPlugin.AddCustomMetadata("build_guid", buildGuid.ToString());
        OVRPlugin.AddCustomMetadata("target_platform", report.summary.platform.ToString());
#if !UNITY_2019_3_OR_NEWER
        OVRPlugin.AddCustomMetadata("scripting_runtime_version", UnityEditor.PlayerSettings.scriptingRuntimeVersion.ToString());
#endif
        if (report.summary.platform == UnityEditor.BuildTarget.StandaloneWindows ||
            report.summary.platform == UnityEditor.BuildTarget.StandaloneWindows64)
        {
            OVRPlugin.AddCustomMetadata("target_oculus_platform", "rift");
        }
#if BUILDSESSION
        StreamWriter writer = new StreamWriter("build_session", false);
        UnityEngine.Debug.LogFormat("Build Session: {0}", buildGuid.ToString());
        writer.WriteLine(buildGuid.ToString());
        writer.Close();
#endif
    }
Exemple #5
0
    public void OnPostGenerateGradleAndroidProject(string path)
    {
        UnityEngine.Debug.Log("OVRGradleGeneration triggered.");
#if UNITY_ANDROID
        var targetOculusPlatform = new List <string>();
        if (OVRDeviceSelector.isTargetDeviceGearVrOrGo)
        {
            targetOculusPlatform.Add("geargo");
        }
        if (OVRDeviceSelector.isTargetDeviceQuest)
        {
            targetOculusPlatform.Add("quest");
        }
        OVRPlugin.AddCustomMetadata("target_oculus_platform", String.Join("_", targetOculusPlatform.ToArray()));
        UnityEngine.Debug.LogFormat("  GearVR or Go = {0}  Quest = {1}", OVRDeviceSelector.isTargetDeviceGearVrOrGo, OVRDeviceSelector.isTargetDeviceQuest);

        bool isQuestOnly = OVRDeviceSelector.isTargetDeviceQuest && !OVRDeviceSelector.isTargetDeviceGearVrOrGo;

        if (isQuestOnly)
        {
            if (File.Exists(Path.Combine(path, "build.gradle")))
            {
                try
                {
                    string gradle = File.ReadAllText(Path.Combine(path, "build.gradle"));

                    int v2Signingindex = gradle.IndexOf("v2SigningEnabled false");
                    if (v2Signingindex != -1)
                    {
                        gradle = gradle.Replace("v2SigningEnabled false", "v2SigningEnabled true");
                        System.IO.File.WriteAllText(Path.Combine(path, "build.gradle"), gradle);
                    }
                }
                catch (System.Exception e)
                {
                    UnityEngine.Debug.LogWarningFormat("Unable to overwrite build.gradle, error {0}", e.Message);
                }
            }
            else
            {
                UnityEngine.Debug.LogWarning("Unable to locate build.gradle");
            }
        }

        PatchAndroidManifest(path);
#endif
    }
Exemple #6
0
    public void OnPreprocessBuild(BuildReport report)
    {
#if UNITY_ANDROID && !(USING_XR_SDK && UNITY_2019_3_OR_NEWER)
        // Generate error when Vulkan is selected as the perferred graphics API, which is not currently supported in Unity XR
        if (!PlayerSettings.GetUseDefaultGraphicsAPIs(BuildTarget.Android))
        {
            GraphicsDeviceType[] apis = PlayerSettings.GetGraphicsAPIs(BuildTarget.Android);
            if (apis.Length >= 1 && apis[0] == GraphicsDeviceType.Vulkan)
            {
                throw new BuildFailedException("The Vulkan Graphics API does not support XR in your configuration. To use Vulkan, you must use Unity 2019.3 or newer, and the XR Plugin Management.");
            }
        }
#endif

        buildStartTime = System.DateTime.Now;
        buildGuid      = System.Guid.NewGuid();

        if (!report.summary.outputPath.Contains("OVRGradleTempExport"))
        {
            OVRPlugin.SetDeveloperMode(OVRPlugin.Bool.True);
            OVRPlugin.AddCustomMetadata("build_type", "standard");
        }

        OVRPlugin.AddCustomMetadata("build_guid", buildGuid.ToString());
        OVRPlugin.AddCustomMetadata("target_platform", report.summary.platform.ToString());
#if !UNITY_2019_3_OR_NEWER
        OVRPlugin.AddCustomMetadata("scripting_runtime_version", UnityEditor.PlayerSettings.scriptingRuntimeVersion.ToString());
#endif
        if (report.summary.platform == UnityEditor.BuildTarget.StandaloneWindows ||
            report.summary.platform == UnityEditor.BuildTarget.StandaloneWindows64)
        {
            OVRPlugin.AddCustomMetadata("target_oculus_platform", "rift");
        }
#if BUILDSESSION
        StreamWriter writer = new StreamWriter("build_session", false);
        UnityEngine.Debug.LogFormat("Build Session: {0}", buildGuid.ToString());
        writer.WriteLine(buildGuid.ToString());
        writer.Close();
#endif
    }
Exemple #7
0
    public void OnPostprocessBuild(BuildReport report)
    {
#if UNITY_ANDROID
        if (autoIncrementVersion)
        {
            if ((report.summary.options & BuildOptions.Development) == 0)
            {
                PlayerSettings.Android.bundleVersionCode++;
                UnityEngine.Debug.Log("Incrementing version code to " + PlayerSettings.Android.bundleVersionCode);
            }
        }

        bool isExporting = true;
        foreach (var step in report.steps)
        {
            if (step.name.Contains("Compile scripts") ||
                step.name.Contains("Building scenes") ||
                step.name.Contains("Writing asset files") ||
                step.name.Contains("Preparing APK resources") ||
                step.name.Contains("Creating Android manifest") ||
                step.name.Contains("Processing plugins") ||
                step.name.Contains("Exporting project") ||
                step.name.Contains("Building Gradle project"))
            {
                OVRPlugin.SendEvent("build_step_" + step.name.ToLower().Replace(' ', '_'),
                                    step.duration.TotalSeconds.ToString(), "ovrbuild");
#if BUILDSESSION
                UnityEngine.Debug.LogFormat("build_step_" + step.name.ToLower().Replace(' ', '_') + ": {0}", step.duration.TotalSeconds.ToString());
#endif
                if (step.name.Contains("Building Gradle project"))
                {
                    isExporting = false;
                }
            }
        }
        OVRPlugin.AddCustomMetadata("build_step_count", report.steps.Length.ToString());
        if (report.summary.outputPath.Contains("apk"))         // Exclude Gradle Project Output
        {
            var fileInfo = new System.IO.FileInfo(report.summary.outputPath);
            OVRPlugin.AddCustomMetadata("build_output_size", fileInfo.Length.ToString());
        }
#endif
        if (!report.summary.outputPath.Contains("OVRGradleTempExport"))
        {
            OVRPlugin.SendEvent("build_complete", (System.DateTime.Now - buildStartTime).TotalSeconds.ToString(), "ovrbuild");
#if BUILDSESSION
            UnityEngine.Debug.LogFormat("build_complete: {0}", (System.DateTime.Now - buildStartTime).TotalSeconds.ToString());
#endif
        }

#if UNITY_ANDROID
        if (!isExporting)
        {
            // Get the hosts path to Android SDK
            if (adbTool == null)
            {
                adbTool = new OVRADBTool(OVRConfig.Instance.GetAndroidSDKPath(false));
            }

            if (adbTool.isReady)
            {
                // Check to see if there are any ADB devices connected before continuing.
                List <string> devices = adbTool.GetDevices();
                if (devices.Count == 0)
                {
                    return;
                }

                // Clear current logs on device
                Process adbClearProcess;
                adbClearProcess = adbTool.RunCommandAsync(new string[] { "logcat --clear" }, null);

                // Add a timeout if we cannot get a response from adb logcat --clear in time.
                Stopwatch timeout = new Stopwatch();
                timeout.Start();
                while (!adbClearProcess.WaitForExit(100))
                {
                    if (timeout.ElapsedMilliseconds > 2000)
                    {
                        adbClearProcess.Kill();
                        return;
                    }
                }

                // Check if existing ADB process is still running, kill if needed
                if (adbProcess != null && !adbProcess.HasExited)
                {
                    adbProcess.Kill();
                }

                // Begin thread to time upload and install
                var thread = new Thread(delegate()
                {
                    TimeDeploy();
                });
                thread.Start();
            }
        }
#endif
    }
Exemple #8
0
    public void OnPostGenerateGradleAndroidProject(string path)
    {
        UnityEngine.Debug.Log("OVRGradleGeneration triggered.");

        var targetOculusPlatform = new List <string>();

        if (OVRDeviceSelector.isTargetDeviceGearVrOrGo)
        {
            targetOculusPlatform.Add("geargo");
        }
        if (OVRDeviceSelector.isTargetDeviceQuest)
        {
            targetOculusPlatform.Add("quest");
        }
        OVRPlugin.AddCustomMetadata("target_oculus_platform", String.Join("_", targetOculusPlatform.ToArray()));
        UnityEngine.Debug.LogFormat("  GearVR or Go = {0}  Quest = {1}", OVRDeviceSelector.isTargetDeviceGearVrOrGo, OVRDeviceSelector.isTargetDeviceQuest);

#if UNITY_2019_3_OR_NEWER
        string gradleBuildPath = Path.Combine(path, "../launcher/build.gradle");
#else
        string gradleBuildPath = Path.Combine(path, "build.gradle");
#endif
        //Enable v2signing for Quest only
        bool v2SigningEnabled = OVRDeviceSelector.isTargetDeviceQuest && !OVRDeviceSelector.isTargetDeviceGearVrOrGo;

        if (File.Exists(gradleBuildPath))
        {
            try
            {
                string gradle         = File.ReadAllText(gradleBuildPath);
                int    v2Signingindex = gradle.IndexOf("v2SigningEnabled false");

                if (v2Signingindex != -1)
                {
                    //v2 Signing flag found, ensure the correct value is set based on platform.
                    if (v2SigningEnabled)
                    {
                        gradle = gradle.Replace("v2SigningEnabled false", "v2SigningEnabled true");
                        System.IO.File.WriteAllText(gradleBuildPath, gradle);
                    }
                }
                else
                {
                    //v2 Signing flag missing, add it right after the key store password and set the value based on platform.
                    int keyPassIndex = gradle.IndexOf("keyPassword");
                    if (keyPassIndex != -1)
                    {
                        int v2Index = gradle.IndexOf("\n", keyPassIndex) + 1;
                        if (v2Index != -1)
                        {
                            gradle = gradle.Insert(v2Index, "v2SigningEnabled " + (v2SigningEnabled ? "true" : "false") + "\n");
                            System.IO.File.WriteAllText(gradleBuildPath, gradle);
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                UnityEngine.Debug.LogWarningFormat("Unable to overwrite build.gradle, error {0}", e.Message);
            }
        }
        else
        {
            UnityEngine.Debug.LogWarning("Unable to locate build.gradle");
        }

        PatchAndroidManifest(path);
    }
    public void OnPostGenerateGradleAndroidProject(string path)
    {
        UnityEngine.Debug.Log("OVRGradleGeneration triggered.");

        var targetOculusPlatform = new List <string>();

        if (OVRDeviceSelector.isTargetDeviceQuestFamily)
        {
            targetOculusPlatform.Add("quest");
        }
        OVRPlugin.AddCustomMetadata("target_oculus_platform", String.Join("_", targetOculusPlatform.ToArray()));
        UnityEngine.Debug.LogFormat("QuestFamily = {0}: Quest = {1}, Quest2 = {2}",
                                    OVRDeviceSelector.isTargetDeviceQuestFamily,
                                    OVRDeviceSelector.isTargetDeviceQuest,
                                    OVRDeviceSelector.isTargetDeviceQuest2);

#if UNITY_2019_3_OR_NEWER
        string gradleBuildPath = Path.Combine(path, "../launcher/build.gradle");
#else
        string gradleBuildPath = Path.Combine(path, "build.gradle");
#endif
        bool v2SigningEnabled = true;

        if (File.Exists(gradleBuildPath))
        {
            try
            {
                string gradle         = File.ReadAllText(gradleBuildPath);
                int    v2Signingindex = gradle.IndexOf("v2SigningEnabled false");

                if (v2Signingindex != -1)
                {
                    //v2 Signing flag found, ensure the correct value is set based on platform.
                    if (v2SigningEnabled)
                    {
                        gradle = gradle.Replace("v2SigningEnabled false", "v2SigningEnabled true");
                        System.IO.File.WriteAllText(gradleBuildPath, gradle);
                    }
                }
                else
                {
                    //v2 Signing flag missing, add it right after the key store password and set the value based on platform.
                    int keyPassIndex = gradle.IndexOf("keyPassword");
                    if (keyPassIndex != -1)
                    {
                        int v2Index = gradle.IndexOf("\n", keyPassIndex) + 1;
                        if (v2Index != -1)
                        {
                            gradle = gradle.Insert(v2Index, "v2SigningEnabled " + (v2SigningEnabled ? "true" : "false") + "\n");
                            System.IO.File.WriteAllText(gradleBuildPath, gradle);
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                UnityEngine.Debug.LogWarningFormat("Unable to overwrite build.gradle, error {0}", e.Message);
            }
        }
        else
        {
            UnityEngine.Debug.LogWarning("Unable to locate build.gradle");
        }

        OVRProjectConfig projectConfig = OVRProjectConfig.GetProjectConfig();
        if (projectConfig != null && projectConfig.systemSplashScreen != null)
        {
            if (PlayerSettings.virtualRealitySplashScreen != null)
            {
                UnityEngine.Debug.LogWarning("Virtual Reality Splash Screen (in Player Settings) is active. It would be displayed after the system splash screen, before the first game frame be rendered.");
            }
            string splashScreenAssetPath = AssetDatabase.GetAssetPath(projectConfig.systemSplashScreen);
            if (Path.GetExtension(splashScreenAssetPath).ToLower() != ".png")
            {
                throw new BuildFailedException("Invalid file format of System Splash Screen. It has to be a PNG file to be used by the Quest OS. The asset path: " + splashScreenAssetPath);
            }
            else
            {
                string sourcePath   = splashScreenAssetPath;
                string targetFolder = Path.Combine(path, "src/main/assets");
                string targetPath   = targetFolder + "/vr_splash.png";
                UnityEngine.Debug.LogFormat("Copy splash screen asset from {0} to {1}", sourcePath, targetPath);
                try
                {
                    File.Copy(sourcePath, targetPath);
                }
                catch (Exception e)
                {
                    throw new BuildFailedException(e.Message);
                }
            }
        }

        PatchAndroidManifest(path);
    }
Exemple #10
0
    public static bool DeployAPK()
    {
        // Create new instance of ADB Tool
        var adbTool = new OVRADBTool(androidSdkPath);

        if (adbTool.isReady)
        {
            string apkPathLocal;
            string gradleExportFolder = Path.Combine(Path.Combine(gradleExport, productName), "build\\outputs\\apk\\debug");

            // Check to see if gradle output directory exists
            gradleExportFolder = gradleExportFolder.Replace("/", "\\");
            if (!Directory.Exists(gradleExportFolder))
            {
                UnityEngine.Debug.LogError("Could not find the gradle project at the expected path: " + gradleExportFolder);
                return(false);
            }

            // Search for output APK in gradle output directory
            apkPathLocal = Path.Combine(gradleExportFolder, productName + "-debug.apk");
            if (!System.IO.File.Exists(apkPathLocal))
            {
                UnityEngine.Debug.LogError(string.Format("Could not find {0} in the gradle project.", productName + "-debug.apk"));
                return(false);
            }

            string   output, error;
            DateTime timerStart;

            // Ensure that the Oculus temp directory is on the device by making it
            IncrementProgressBar("Making Temp directory on device");
            string[] mkdirCommand = { "-d shell", "mkdir -p", REMOTE_APK_PATH };
            if (adbTool.RunCommand(mkdirCommand, null, out output, out error) != 0)
            {
                return(false);
            }

            // Push APK to device, also time how long it takes
            timerStart = System.DateTime.Now;
            IncrementProgressBar("Pushing APK to device . . .");
            string[] pushCommand = { "-d push", "\"" + apkPathLocal + "\"", REMOTE_APK_PATH };
            if (adbTool.RunCommand(pushCommand, null, out output, out error) != 0)
            {
                return(false);
            }

            // Calculate the transfer speed and determine if user is using USB 2.0 or 3.0
            TimeSpan pushTime      = System.DateTime.Now - timerStart;
            FileInfo apkInfo       = new System.IO.FileInfo(apkPathLocal);
            double   transferSpeed = (apkInfo.Length / pushTime.TotalSeconds) / BYTES_TO_MEGABYTES;
            bool     informLog     = transferSpeed < USB_TRANSFER_SPEED_THRES;
            UnityEngine.Debug.Log("OVRADBTool: Push Success");

            // Install the APK package on the device
            IncrementProgressBar("Installing APK . . .");
            string apkPath = REMOTE_APK_PATH + "/" + productName + "-debug.apk";
            apkPath = apkPath.Replace(" ", "\\ ");
            string[] installCommand = { "-d shell", "pm install -r", apkPath };

            timerStart = System.DateTime.Now;
            if (adbTool.RunCommand(installCommand, null, out output, out error) != 0)
            {
                return(false);
            }
            TimeSpan installTime = System.DateTime.Now - timerStart;
            UnityEngine.Debug.Log("OVRADBTool: Install Success");

            // Start the application on the device
            IncrementProgressBar("Launching application on device . . .");
#if UNITY_2019_3_OR_NEWER
            string playerActivityName = "\"" + applicationIdentifier + "/com.unity3d.player.UnityPlayerActivity\"";
#else
            string playerActivityName = "\"" + applicationIdentifier + "/" + applicationIdentifier + ".UnityPlayerActivity\"";
#endif
            string[] appStartCommand = { "-d shell", "am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -S -f 0x10200000 -n", playerActivityName };
            if (adbTool.RunCommand(appStartCommand, null, out output, out error) != 0)
            {
                return(false);
            }
            UnityEngine.Debug.Log("OVRADBTool: Application Start Success");

            // Send back metrics on push and install steps
            OVRPlugin.AddCustomMetadata("transfer_speed", transferSpeed.ToString());
            OVRPlugin.SendEvent("build_step_push_apk", pushTime.TotalSeconds.ToString(), "ovrbuild");
            OVRPlugin.SendEvent("build_step_install_apk", installTime.TotalSeconds.ToString(), "ovrbuild");

            IncrementProgressBar("Success!");

            // If the user is using a USB 2.0 cable, inform them about improved transfer speeds and estimate time saved
            if (informLog)
            {
                var usb3Time = apkInfo.Length / (USB_3_TRANSFER_SPEED * BYTES_TO_MEGABYTES);
                UnityEngine.Debug.Log(string.Format("OVRBuild has detected slow transfer speeds. A USB 3.0 cable is recommended to reduce the time it takes to deploy your project by approximatly {0:0.0} seconds", pushTime.TotalSeconds - usb3Time));
                return(true);
            }
        }
        else
        {
            UnityEngine.Debug.LogError("Could not find the ADB executable in the specified Android SDK directory.");
        }
        return(false);
    }
Exemple #11
0
    static void StartBuildAndRun()
    {
        EditorWindow.GetWindow(typeof(OculusBuildApp));

        showCancel     = false;
        buildFailed    = false;
        totalBuildTime = 0;

        InitializeProgressBar(NUM_BUILD_AND_RUN_STEPS);
        IncrementProgressBar("Exporting Unity Project . . .");

        OVRPlugin.SetDeveloperMode(OVRPlugin.Bool.True);
        OVRPlugin.AddCustomMetadata("build_type", "ovr_build_and_run");

        if (!CheckADBDevices())
        {
            buildFailed = true;
            return;
        }

        // Record OVR Build and Run start event
        OVRPlugin.SendEvent("ovr_build_and_run_start", "", "ovrbuild");

        apkOutputSuccessful = null;
        syncCancelToken     = null;
        gradleBuildProcess  = null;

        UnityEngine.Debug.Log("OVRBuild: Starting Unity build ...");

        SetupDirectories();

        // 1. Get scenes to build in Unity, and export gradle project
        var buildResult = UnityBuildPlayer();

        if (buildResult.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded)
        {
            foreach (var step in buildResult.steps)
            {
                // Only log top level build steps & specific nested steps to reduce the number of events sent
                if (step.depth == 1 ||
                    (step.name.StartsWith("Packaging assets") && step.name.EndsWith(".assets")) ||
                    step.name.Equals("Managed Stripping: (Mono)") ||
                    step.name.Equals("Splitting assets") ||
                    step.name.Equals("IL2CPP") ||
                    step.name.Equals("Exporting project")
                    )
                {
                    OVRPlugin.SendEvent($"build_step_unity_build_player {step.name}", step.duration.TotalSeconds.ToString(), "ovrbuild");
                }
            }

            OVRPlugin.SendEvent("build_step_unity_export", buildResult.summary.totalTime.TotalSeconds.ToString(), "ovrbuild");
            totalBuildTime += buildResult.summary.totalTime.TotalSeconds;

            // Set static variables so build thread has updated data
            showCancel            = true;
            gradlePath            = OVRConfig.Instance.GetGradlePath();
            jdkPath               = OVRConfig.Instance.GetJDKPath();
            androidSdkPath        = OVRConfig.Instance.GetAndroidSDKPath();
            applicationIdentifier = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android);
#if UNITY_2019_3_OR_NEWER
            productName = "launcher";
#else
            productName = Application.productName;
#endif
            dataPath = Application.dataPath;

            buildThread = new Thread(delegate()
            {
                OVRBuildRun();
            });
            buildThread.Start();
            return;
        }
        else if (buildResult.summary.result == UnityEditor.Build.Reporting.BuildResult.Cancelled)
        {
            UnityEngine.Debug.Log("Build cancelled.");
        }
        else
        {
            UnityEngine.Debug.Log("Build failed.");
        }
        buildFailed = true;
    }
Exemple #12
0
    static void StartBuildAndRun()
    {
        EditorWindow.GetWindow(typeof(OculusBuildApp));

        showCancel     = false;
        buildFailed    = false;
        totalBuildTime = 0;

        InitializeProgressBar(NUM_BUILD_AND_RUN_STEPS);
        IncrementProgressBar("Exporting Unity Project . . .");

        OVRPlugin.SetDeveloperMode(OVRPlugin.Bool.True);
        OVRPlugin.AddCustomMetadata("build_type", "ovr_build_and_run");

        if (!CheckADBDevices())
        {
            return;
        }

        // Record OVR Build and Run start event
        OVRPlugin.SendEvent("ovr_build_and_run_start", "", "ovrbuild");

        apkOutputSuccessful = null;
        syncCancelToken     = null;
        gradleBuildProcess  = null;

        UnityEngine.Debug.Log("OVRBuild: Starting Unity build ...");

        SetupDirectories();

        // 1. Get scenes to build in Unity, and export gradle project
        List <string> sceneList        = GetScenesToBuild();
        DateTime      unityExportStart = DateTime.Now;
        var           buildResult      = BuildPipeline.BuildPlayer(sceneList.ToArray(), gradleTempExport, BuildTarget.Android,
                                                                   BuildOptions.AcceptExternalModificationsToPlayer |
                                                                   BuildOptions.Development |
                                                                   BuildOptions.AllowDebugging);

        if (buildResult.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded)
        {
            double unityExportTime = (DateTime.Now - unityExportStart).TotalSeconds;
            OVRPlugin.SendEvent("build_step_unity_export", unityExportTime.ToString(), "ovrbuild");
            totalBuildTime += unityExportTime;

            // Set static variables so build thread has updated data
            showCancel            = true;
            gradlePath            = OVRConfig.Instance.GetGradlePath();
            jdkPath               = OVRConfig.Instance.GetJDKPath();
            androidSdkPath        = OVRConfig.Instance.GetAndroidSDKPath();
            applicationIdentifier = PlayerSettings.applicationIdentifier;
            productName           = Application.productName;
            dataPath              = Application.dataPath;

            buildThread = new Thread(delegate()
            {
                OVRBuildRun();
            });
            buildThread.Start();
            return;
        }
        else if (buildResult.summary.result == UnityEditor.Build.Reporting.BuildResult.Cancelled)
        {
            UnityEngine.Debug.Log("Build cancelled.");
        }
        else
        {
            UnityEngine.Debug.Log("Build failed.");
        }
        buildFailed = true;
    }