Skip to content

Commit

Permalink
Xr add open xr configs (#12)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Ejaz Ahmed Mudassir authored and GitHub Enterprise committed Nov 30, 2021
1 parent 345ca8f commit 11eb653
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 35 additions & 1 deletion ConfigureXRProject/OpenXRSettings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using com.unity.cliprojectsetup;
Expand All @@ -20,12 +21,25 @@ class OpenXRPlatformSettings : XrSdkPlatformSettings<OpenXRSettings, OpenXRLoade
protected override string xrConfigName => UnityEngine.XR.OpenXR.Constants.k_SettingsKey;
protected override string CmdlineParam => "OpenXR";

private List<string> 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
Expand All @@ -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<UnityEngine.XR.OpenXR.Features.Interactions.MicrosoftMotionControllerProfile>();

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();
}
Expand Down
7 changes: 6 additions & 1 deletion ConfigureXRProject/XRSDKPlatformSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ protected virtual void CreateXRSettingsInstance()
xrSettings = ScriptableObject.CreateInstance<T>();
}

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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 11eb653

Please sign in to comment.