From 11eb653e0f9f91c645c5255b00174931883014d6 Mon Sep 17 00:00:00 2001 From: Ejaz Ahmed Mudassir Date: Mon, 29 Nov 2021 16:42:29 -0800 Subject: [PATCH] Xr add open xr configs (#12) * Add mock runtime configs * Revert changes from master * Update split function use char instead of string * Update split method * Bump Version * Update according to review comment * Update type in debug text Tests performed: https://unity-ci.cds.internal.unity3d.com/job/9996854 https://unity-ci.cds.internal.unity3d.com/job/9040853 --- CHANGELOG.md | 3 ++ ConfigureXRProject/OpenXRSettings.cs | 36 ++++++++++++++++++++- ConfigureXRProject/XRSDKPlatformSettings.cs | 7 +++- package.json | 2 +- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 609d075..cce2e21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.3.14-preview] - 2021-11-17 +* Add OpenXR configuration + ## [0.3.13-preview] - 2021-09-13 * Update metadata manager dependency diff --git a/ConfigureXRProject/OpenXRSettings.cs b/ConfigureXRProject/OpenXRSettings.cs index 0b0f052..d4382b2 100644 --- a/ConfigureXRProject/OpenXRSettings.cs +++ b/ConfigureXRProject/OpenXRSettings.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Linq; using com.unity.cliprojectsetup; @@ -20,12 +21,25 @@ class OpenXRPlatformSettings : XrSdkPlatformSettings UnityEngine.XR.OpenXR.Constants.k_SettingsKey; protected override string CmdlineParam => "OpenXR"; + private List OpenXrFeatures; + protected override void CreateXRSettingsInstance() { FeatureHelpers.RefreshFeatures(EditorUserBuildSettings.selectedBuildTargetGroup); xrSettings = OpenXRSettings.ActiveBuildTargetInstance; } - + + protected override bool IsXrTarget(string xrTarget) + { + if (xrTarget.StartsWith(CmdlineParam, StringComparison.OrdinalIgnoreCase)) + { + OpenXrFeatures = xrTarget.Split(new char[]{'.'}, StringSplitOptions.RemoveEmptyEntries).ToList(); + return true; + } + + return false; + } + public override void SetRenderMode(PlatformSettings platformSettings) { try @@ -41,6 +55,26 @@ public override void SetRenderMode(PlatformSettings platformSettings) public override void ApplyLoaderSettings(XRGeneralSettingsPerBuildTarget buildTargetSettings) { + FeatureHelpers.RefreshFeatures(BuildTargetGroup.Standalone); + var msController = OpenXRSettings.ActiveBuildTargetInstance + .GetFeature(); + + if (OpenXrFeatures.Contains("MockRT")) + { + Debug.Log("Enabling Mock Runtime Feature"); + + var feature = OpenXRSettings.Instance.GetFeatures().Where(f => f.GetType().Name == "MockRuntime").FirstOrDefault(); + feature.enabled = true; + feature.GetType().GetField("ignoreValidationErrors").SetValue(feature, true); + } + else + { + if (msController) + { + msController.enabled = true; + EditorUtility.SetDirty(OpenXRSettings.ActiveBuildTargetInstance); + } + } EditorUtility.SetDirty(OpenXRSettings.ActiveBuildTargetInstance); AssetDatabase.SaveAssets(); } diff --git a/ConfigureXRProject/XRSDKPlatformSettings.cs b/ConfigureXRProject/XRSDKPlatformSettings.cs index 4e76c26..c8b2260 100644 --- a/ConfigureXRProject/XRSDKPlatformSettings.cs +++ b/ConfigureXRProject/XRSDKPlatformSettings.cs @@ -28,9 +28,14 @@ protected virtual void CreateXRSettingsInstance() xrSettings = ScriptableObject.CreateInstance(); } + protected virtual bool IsXrTarget(string xrTarget) + { + return xrTarget.Equals(CmdlineParam, StringComparison.OrdinalIgnoreCase); + } + protected override void ConfigureXr(PlatformSettings platformSettings) { - if (!string.Equals(CmdlineParam, platformSettings.XrTarget, StringComparison.OrdinalIgnoreCase)) + if (!IsXrTarget(platformSettings.XrTarget)) { return; } diff --git a/package.json b/package.json index ee12ed0..00e746a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.cli-project-setup", "displayName": "Unity CLI Project Setup", - "version": "0.3.13-preview", + "version": "0.3.14-preview", "unity": "2019.4", "description": "Provides a command line parser and options to set build, player, and other Unity settings when running Unity from the command line.", "dependencies": {