Skip to content

Commit 2d2c455

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/MixedRealityToolkit-Unity into feature/uber-profile
2 parents 9563901 + 87d1c35 commit 2d2c455

File tree

47 files changed

+489
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+489
-64
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using Microsoft.MixedReality.Toolkit.Utilities;
5+
using System;
6+
using System.Runtime.CompilerServices;
7+
using UnityEngine;
8+
using UnityEngine.Serialization;
9+
10+
[assembly: InternalsVisibleTo("Microsoft.MixedReality.Toolkit.Tests.EditModeTests")]
11+
[assembly: InternalsVisibleTo("Microsoft.MixedReality.Toolkit.Tests.PlayModeTests")]
12+
namespace Microsoft.MixedReality.Toolkit
13+
{
14+
/// <summary>
15+
/// Experience settings profile for the Mixed Reality Toolkit.
16+
/// </summary>
17+
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Profiles/Mixed Reality Toolkit Experience Settings Profile", fileName = "MixedRealityToolkitExperienceSettingsProfile", order = (int)CreateProfileMenuItemIndices.Configuration)]
18+
[HelpURL("https://docs.microsoft.com/windows/mixed-reality/mrtk-unity/configuration/mixed-reality-configuration-guide")]
19+
public class MixedRealityExperienceSettingsProfile : BaseMixedRealityProfile
20+
{
21+
[SerializeField]
22+
[Tooltip("The scale of the Mixed Reality experience.")]
23+
private ExperienceScale targetExperienceScale = ExperienceScale.Room;
24+
25+
/// <summary>
26+
/// The desired the scale of the experience.
27+
/// </summary>
28+
public ExperienceScale TargetExperienceScale
29+
{
30+
get { return targetExperienceScale; }
31+
set { targetExperienceScale = value; }
32+
}
33+
34+
[SerializeField]
35+
[Tooltip("The amount to offset the MixedRealitySceneContent for the target experience. 1 unit = 1 meter")]
36+
private float contentOffset = 0.0f;
37+
38+
/// <summary>
39+
/// The height above the floor for the Mixed Reality Experience. 1 unit = 1 meter
40+
/// </summary>
41+
public float ContentOffset
42+
{
43+
get { return contentOffset; }
44+
set { contentOffset = value; }
45+
}
46+
}
47+
}

Assets/MRTK/Core/Definitions/MixedRealityExperienceSettingsProfile.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/MRTK/Core/Definitions/MixedRealityToolkitConfigurationProfile.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,34 @@ public class MixedRealityToolkitConfigurationProfile : BaseMixedRealityProfile
2727
{
2828
#region Mixed Reality Toolkit configurable properties
2929

30+
[SerializeField]
31+
[Tooltip("Experience Settings profile.")]
32+
private MixedRealityExperienceSettingsProfile experienceSettingsProfile;
33+
34+
/// <summary>
35+
/// Profile for configuring the experience settings of your project.
36+
/// Determines whether your project targers AR/VR, the scale of your experience, and the height of the user where applicable
37+
/// </summary>
38+
public MixedRealityExperienceSettingsProfile ExperienceSettingsProfile
39+
{
40+
get { return experienceSettingsProfile; }
41+
internal set { experienceSettingsProfile = value; }
42+
}
43+
44+
3045
[SerializeField]
3146
[Tooltip("The scale of the Mixed Reality experience.")]
3247
private ExperienceScale targetExperienceScale = ExperienceScale.Room;
3348

3449
/// <summary>
3550
/// The desired the scale of the experience.
51+
/// Profile for configuring the experience settings of your project.
52+
/// Determines whether your project targers AR/VR, the scale of your experience, and the height of the user where applicable
3653
/// </summary>
54+
/// <remarks>
55+
/// The target experience scale is now configured via ExperienceSettingsProfile
56+
/// </remarks>
57+
[Obsolete("The target experience scale is now configured via ExperienceSettingsProfile, please use the ExperienceSettingsProfile.TargetExperienceScale instead")]
3758
public ExperienceScale TargetExperienceScale
3859
{
3960
get { return targetExperienceScale; }

Assets/MRTK/Core/Inspectors/Profiles/BaseMixedRealityProfileInspector.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ public static void RenderReadOnlyProfile(SerializedProperty property)
7373
/// <param name="showCloneButton">If true, draw the clone button, if false, don't</param>
7474
/// <param name="renderProfileInBox">if true, render box around profile content, if false, don't</param>
7575
/// <param name="serviceType">Optional service type to limit available profile types.</param>
76+
/// <param name="profileRequiredOverride">Optional parameter to used to specify that a profile must be selected</param>
7677
/// <returns>True, if the profile changed.</returns>
77-
protected static bool RenderProfile(SerializedProperty property, Type profileType, bool showCloneButton = true, bool renderProfileInBox = false, Type serviceType = null)
78+
protected static bool RenderProfile(SerializedProperty property, Type profileType, bool showCloneButton = true, bool renderProfileInBox = false, Type serviceType = null, bool profileRequiredOverride = false)
7879
{
79-
return RenderProfileInternal(property, profileType, showCloneButton, renderProfileInBox, serviceType);
80+
return RenderProfileInternal(property, profileType, showCloneButton, renderProfileInBox, serviceType, profileRequiredOverride);
8081
}
8182

8283
/// <summary>
@@ -86,9 +87,10 @@ protected static bool RenderProfile(SerializedProperty property, Type profileTyp
8687
/// <param name="showCloneButton">If true, draw the clone button, if false, don't</param>
8788
/// <param name="renderProfileInBox">if true, render box around profile content, if false, don't</param>
8889
/// <param name="serviceType">Optional service type to limit available profile types.</param>
90+
/// <param name="profileRequiredOverride">Optional parameter to used to specify that a profile must be selected</param>
8991
/// <returns>True, if the profile changed.</returns>
9092
private static bool RenderProfileInternal(SerializedProperty property, Type profileType,
91-
bool showCloneButton, bool renderProfileInBox, Type serviceType = null)
93+
bool showCloneButton, bool renderProfileInBox, Type serviceType = null, bool profileRequiredOverride = false)
9294
{
9395
var profile = property.serializedObject.targetObject as BaseMixedRealityProfile;
9496
bool changed = false;
@@ -112,7 +114,7 @@ private static bool RenderProfileInternal(SerializedProperty property, Type prof
112114

113115
Type[] profileTypes = new Type[] { };
114116

115-
bool requiresProfile = IsProfileRequired(serviceType);
117+
bool requiresProfile = IsProfileRequired(serviceType) || profileRequiredOverride;
116118
if (profileType == null)
117119
{
118120
// Find the profile type so we can limit the available object field options

Assets/MRTK/Core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ public class MixedRealityToolkitConfigurationProfileInspector : BaseMixedReality
2121
private static readonly GUIContent TargetScaleContent = new GUIContent("Target Scale:");
2222

2323
// Experience properties
24-
private SerializedProperty targetExperienceScale;
24+
private SerializedProperty experienceSettingsType;
25+
private SerializedProperty experienceSettingsProfile;
26+
27+
// Tracking the old experience scale property for compatibility
28+
private SerializedProperty experienceScaleMigration;
29+
2530
// Camera properties
2631
private SerializedProperty enableCameraSystem;
2732
private SerializedProperty cameraSystemType;
@@ -62,6 +67,7 @@ public class MixedRealityToolkitConfigurationProfileInspector : BaseMixedReality
6267
private Func<bool>[] renderProfileFuncs;
6368

6469
private static readonly string[] ProfileTabTitles = {
70+
"Experience Settings",
6571
"Camera",
6672
"Input",
6773
"Boundary",
@@ -91,7 +97,10 @@ protected override void OnEnable()
9197
MixedRealityToolkitConfigurationProfile mrtkConfigProfile = target as MixedRealityToolkitConfigurationProfile;
9298

9399
// Experience configuration
94-
targetExperienceScale = serializedObject.FindProperty("targetExperienceScale");
100+
experienceSettingsType = serializedObject.FindProperty("experienceSettingsType");
101+
experienceSettingsProfile = serializedObject.FindProperty("experienceSettingsProfile");
102+
experienceScaleMigration = serializedObject.FindProperty("targetExperienceScale");
103+
95104
// Camera configuration
96105
enableCameraSystem = serializedObject.FindProperty("enableCameraSystem");
97106
cameraSystemType = serializedObject.FindProperty("cameraSystemType");
@@ -139,6 +148,56 @@ protected override void OnEnable()
139148
{
140149
renderProfileFuncs = new Func<bool>[]
141150
{
151+
() => {
152+
bool changed = false;
153+
using (var c = new EditorGUI.ChangeCheckScope())
154+
{
155+
// Reconciling old Experience Scale property with the Experience Settings Profile
156+
var oldExperienceSettigsScale = (experienceSettingsProfile.objectReferenceValue as MixedRealityExperienceSettingsProfile)?.TargetExperienceScale;
157+
158+
changed |= RenderProfile(experienceSettingsProfile, typeof(MixedRealityExperienceSettingsProfile), true, false, null, true);
159+
160+
// Experience configuration
161+
if(!mrtkConfigProfile.ExperienceSettingsProfile.IsNull())
162+
{
163+
// If the Experience Scale property changed, make sure we also alter the configuration profile's target experience scale property for compatibility
164+
var newExperienceSettigs = (experienceSettingsProfile.objectReferenceValue as MixedRealityExperienceSettingsProfile)?.TargetExperienceScale;
165+
if(oldExperienceSettigsScale.HasValue && newExperienceSettigs.HasValue && oldExperienceSettigsScale != newExperienceSettigs)
166+
{
167+
experienceScaleMigration.intValue = (int)newExperienceSettigs;
168+
experienceScaleMigration.serializedObject.ApplyModifiedProperties();
169+
}
170+
// If we have not changed the Experience Settings profile and it's value is out of sync with the top level configuration profile, display a migration prompt
171+
else if ((ExperienceScale)experienceScaleMigration.intValue != mrtkConfigProfile.ExperienceSettingsProfile.TargetExperienceScale)
172+
{
173+
Color errorColor = Color.Lerp(Color.white, Color.red, 0.5f);
174+
Color defaultColor = GUI.color;
175+
176+
GUI.color = errorColor;
177+
EditorGUILayout.HelpBox("A previous version of this profile has a different Experience Scale, displayed below. Please modify the Experience Setting Profile's Target Experience Scale or select your desired scale below", MessageType.Warning);
178+
var oldValue = experienceScaleMigration.intValue;
179+
EditorGUILayout.PropertyField(experienceScaleMigration);
180+
if (oldValue != experienceScaleMigration.intValue)
181+
{
182+
mrtkConfigProfile.ExperienceSettingsProfile.TargetExperienceScale = (ExperienceScale)experienceScaleMigration.intValue;
183+
}
184+
GUI.color = defaultColor;
185+
}
186+
187+
188+
ExperienceScale experienceScale = mrtkConfigProfile.ExperienceSettingsProfile.TargetExperienceScale;
189+
string targetExperienceSummary = GetExperienceDescription(experienceScale);
190+
if (!string.IsNullOrEmpty(targetExperienceSummary))
191+
{
192+
EditorGUILayout.HelpBox(targetExperienceSummary, MessageType.None);
193+
EditorGUILayout.Space();
194+
}
195+
}
196+
197+
changed |= c.changed;
198+
}
199+
return changed;
200+
},
142201
() => {
143202
bool changed = false;
144203
using (var c = new EditorGUI.ChangeCheckScope())
@@ -188,7 +247,7 @@ protected override void OnEnable()
188247
return changed;
189248
},
190249
() => {
191-
var experienceScale = (ExperienceScale)targetExperienceScale.intValue;
250+
var experienceScale = mrtkConfigProfile.ExperienceSettingsProfile.TargetExperienceScale;
192251
if (experienceScale != ExperienceScale.Room)
193252
{
194253
// Alert the user if the experience scale does not support boundary features.
@@ -311,7 +370,6 @@ protected override void OnEnable()
311370

312371
changed |= RenderProfile(sceneSystemProfile, typeof(MixedRealitySceneSystemProfile), true, true, typeof(IMixedRealitySceneSystem));
313372
}
314-
315373
changed |= c.changed;
316374
}
317375
return changed;
@@ -407,22 +465,7 @@ public override void OnInspectorGUI()
407465
bool isGUIEnabled = !IsProfileLock((BaseMixedRealityProfile)target) && GUI.enabled;
408466
GUI.enabled = isGUIEnabled;
409467

410-
EditorGUI.BeginChangeCheck();
411468
bool changed = false;
412-
413-
// Experience configuration
414-
ExperienceScale experienceScale = (ExperienceScale)targetExperienceScale.intValue;
415-
EditorGUILayout.PropertyField(targetExperienceScale, TargetScaleContent);
416-
417-
string scaleDescription = GetExperienceDescription(experienceScale);
418-
if (!string.IsNullOrEmpty(scaleDescription))
419-
{
420-
EditorGUILayout.HelpBox(scaleDescription, MessageType.None);
421-
EditorGUILayout.Space();
422-
}
423-
424-
changed |= EditorGUI.EndChangeCheck();
425-
426469
EditorGUILayout.BeginHorizontal();
427470

428471
EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(100));

Assets/MRTK/Core/Inspectors/Utilities/MixedRealityInspectorUtility.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ public static bool CheckMixedRealityConfigured(bool renderEditorElements = false
8787
/// <summary>
8888
/// If MRTK is not initialized in scene, adds and initializes instance to current scene
8989
/// </summary>
90-
public static void AddMixedRealityToolkitToScene(MixedRealityToolkitConfigurationProfile configProfile = null)
90+
public static void AddMixedRealityToolkitToScene(MixedRealityToolkitConfigurationProfile configProfile = null, bool inPlayMode = false)
9191
{
9292
if (!MixedRealityToolkit.IsInitialized)
9393
{
9494
MixedRealityToolkit newInstance = new GameObject("MixedRealityToolkit").AddComponent<MixedRealityToolkit>();
9595
MixedRealityToolkit.SetActiveInstance(newInstance);
9696
Selection.activeObject = newInstance;
9797

98+
MixedRealityToolkit.ConfirmInitialized();
99+
98100
if (configProfile == null)
99101
{
100102
// if we don't have a profile set we get the default profile
@@ -104,7 +106,17 @@ public static void AddMixedRealityToolkitToScene(MixedRealityToolkitConfiguratio
104106
{
105107
newInstance.ActiveProfile = configProfile;
106108
}
107-
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
109+
110+
if(!newInstance.ActiveProfile.ExperienceSettingsProfile.IsNull())
111+
{
112+
// Add a MixedRealitySceneContent object to a scene. Children of this object will scale appropriately dependent on MR platform
113+
MixedRealitySceneContent contentAdjuster = new GameObject("MixedRealitySceneContent").AddComponent<MixedRealitySceneContent>();
114+
}
115+
116+
if (!inPlayMode)
117+
{
118+
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
119+
}
108120
}
109121
}
110122

Assets/MRTK/Core/Providers/BaseCameraSettingsProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ public virtual void ApplyConfiguration()
5151
}
5252
}
5353
}
54-
}
54+
}

Assets/MRTK/Core/Services/MixedRealityToolkit.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ private void InitializeServiceLocator()
470470
}
471471

472472
// If the Boundary system has been selected for initialization in the Active profile, enable it in the project
473-
if (ActiveProfile.IsBoundarySystemEnabled)
473+
if (ActiveProfile.IsBoundarySystemEnabled && !ActiveProfile.ExperienceSettingsProfile.IsNull())
474474
{
475475
DebugUtilities.LogVerbose("Begin registration of the boundary system");
476-
object[] args = { ActiveProfile.BoundaryVisualizationProfile, ActiveProfile.TargetExperienceScale };
476+
object[] args = { ActiveProfile.BoundaryVisualizationProfile, ActiveProfile.ExperienceSettingsProfile.TargetExperienceScale };
477477
if (!RegisterService<IMixedRealityBoundarySystem>(ActiveProfile.BoundarySystemSystemType, args: args) || CoreServices.BoundarySystem == null)
478478
{
479479
Debug.LogError("Failed to start the Boundary System!");

0 commit comments

Comments
 (0)