Created
July 3, 2020 09:46
-
-
Save zeroZshadow/03b65b237e073b8cdf70ee2ebe8856d0 to your computer and use it in GitHub Desktop.
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 System.Collections.Generic; | |
| using Improbable.Gdk.BuildSystem; | |
| using UnityEditor.Build; | |
| using UnityEditor.Build.Reporting; | |
| using UnityEditor.XR.Management; | |
| using UnityEngine; | |
| using UnityEngine.XR.Management; | |
| namespace Editor | |
| { | |
| public class XRBuildPreProcessor : IPreprocessBuildWithReport, IPostprocessBuildWithReport | |
| { | |
| public int callbackOrder { get; } = -1; | |
| private bool initManagerOnStart; | |
| private List<XRLoader> previousLoaders; | |
| public void OnPreprocessBuild(BuildReport report) | |
| { | |
| if (WorkerBuilder.CurrentContext.WorkerType == "UnityClient") | |
| { | |
| return; | |
| } | |
| var generalSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(report.summary.platformGroup); | |
| if (generalSettings == null) | |
| { | |
| return; | |
| } | |
| var settings = generalSettings.AssignedSettings; | |
| if (settings == null) | |
| { | |
| return; | |
| } | |
| // Not building a client, disable XR | |
| Debug.Log("Disabling XR for non-client worker"); | |
| // Copy settings | |
| initManagerOnStart = generalSettings.InitManagerOnStart; | |
| previousLoaders = new List<XRLoader>(settings.loaders); | |
| // Replace loaders with empty list | |
| settings.loaders = new List<XRLoader>(); | |
| } | |
| public void OnPostprocessBuild(BuildReport report) | |
| { | |
| var generalSettings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(report.summary.platformGroup); | |
| if (generalSettings == null) | |
| { | |
| return; | |
| } | |
| var settings = generalSettings.AssignedSettings; | |
| if (settings == null) | |
| { | |
| return; | |
| } | |
| if (previousLoaders != null) | |
| { | |
| Debug.Log("Re-enabling XR"); | |
| settings.loaders = previousLoaders; | |
| previousLoaders = null; | |
| generalSettings.InitManagerOnStart = initManagerOnStart; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment