Skip to content

Commit 0794cd4

Browse files
committed
Merge branch 'main' into add_configurator
2 parents db03e84 + d73d6cd commit 0794cd4

File tree

97 files changed

+1555
-539
lines changed

Some content is hidden

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

97 files changed

+1555
-539
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;
@@ -61,6 +66,7 @@ public class MixedRealityToolkitConfigurationProfileInspector : BaseMixedReality
6166
private Func<bool>[] renderProfileFuncs;
6267

6368
private static readonly string[] ProfileTabTitles = {
69+
"Experience Settings",
6470
"Camera",
6571
"Input",
6672
"Boundary",
@@ -88,7 +94,10 @@ protected override void OnEnable()
8894
MixedRealityToolkitConfigurationProfile mrtkConfigProfile = target as MixedRealityToolkitConfigurationProfile;
8995

9096
// Experience configuration
91-
targetExperienceScale = serializedObject.FindProperty("targetExperienceScale");
97+
experienceSettingsType = serializedObject.FindProperty("experienceSettingsType");
98+
experienceSettingsProfile = serializedObject.FindProperty("experienceSettingsProfile");
99+
experienceScaleMigration = serializedObject.FindProperty("targetExperienceScale");
100+
92101
// Camera configuration
93102
enableCameraSystem = serializedObject.FindProperty("enableCameraSystem");
94103
cameraSystemType = serializedObject.FindProperty("cameraSystemType");
@@ -131,6 +140,56 @@ protected override void OnEnable()
131140
{
132141
renderProfileFuncs = new Func<bool>[]
133142
{
143+
() => {
144+
bool changed = false;
145+
using (var c = new EditorGUI.ChangeCheckScope())
146+
{
147+
// Reconciling old Experience Scale property with the Experience Settings Profile
148+
var oldExperienceSettigsScale = (experienceSettingsProfile.objectReferenceValue as MixedRealityExperienceSettingsProfile)?.TargetExperienceScale;
149+
150+
changed |= RenderProfile(experienceSettingsProfile, typeof(MixedRealityExperienceSettingsProfile), true, false, null, true);
151+
152+
// Experience configuration
153+
if(!mrtkConfigProfile.ExperienceSettingsProfile.IsNull())
154+
{
155+
// If the Experience Scale property changed, make sure we also alter the configuration profile's target experience scale property for compatibility
156+
var newExperienceSettigs = (experienceSettingsProfile.objectReferenceValue as MixedRealityExperienceSettingsProfile)?.TargetExperienceScale;
157+
if(oldExperienceSettigsScale.HasValue && newExperienceSettigs.HasValue && oldExperienceSettigsScale != newExperienceSettigs)
158+
{
159+
experienceScaleMigration.intValue = (int)newExperienceSettigs;
160+
experienceScaleMigration.serializedObject.ApplyModifiedProperties();
161+
}
162+
// 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
163+
else if ((ExperienceScale)experienceScaleMigration.intValue != mrtkConfigProfile.ExperienceSettingsProfile.TargetExperienceScale)
164+
{
165+
Color errorColor = Color.Lerp(Color.white, Color.red, 0.5f);
166+
Color defaultColor = GUI.color;
167+
168+
GUI.color = errorColor;
169+
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);
170+
var oldValue = experienceScaleMigration.intValue;
171+
EditorGUILayout.PropertyField(experienceScaleMigration);
172+
if (oldValue != experienceScaleMigration.intValue)
173+
{
174+
mrtkConfigProfile.ExperienceSettingsProfile.TargetExperienceScale = (ExperienceScale)experienceScaleMigration.intValue;
175+
}
176+
GUI.color = defaultColor;
177+
}
178+
179+
180+
ExperienceScale experienceScale = mrtkConfigProfile.ExperienceSettingsProfile.TargetExperienceScale;
181+
string targetExperienceSummary = GetExperienceDescription(experienceScale);
182+
if (!string.IsNullOrEmpty(targetExperienceSummary))
183+
{
184+
EditorGUILayout.HelpBox(targetExperienceSummary, MessageType.None);
185+
EditorGUILayout.Space();
186+
}
187+
}
188+
189+
changed |= c.changed;
190+
}
191+
return changed;
192+
},
134193
() => {
135194
bool changed = false;
136195
using (var c = new EditorGUI.ChangeCheckScope())
@@ -180,7 +239,7 @@ protected override void OnEnable()
180239
return changed;
181240
},
182241
() => {
183-
var experienceScale = (ExperienceScale)targetExperienceScale.intValue;
242+
var experienceScale = mrtkConfigProfile.ExperienceSettingsProfile.TargetExperienceScale;
184243
if (experienceScale != ExperienceScale.Room)
185244
{
186245
// Alert the user if the experience scale does not support boundary features.
@@ -299,7 +358,6 @@ protected override void OnEnable()
299358

300359
changed |= RenderProfile(sceneSystemProfile, typeof(MixedRealitySceneSystemProfile), true, true, typeof(IMixedRealitySceneSystem));
301360
}
302-
303361
changed |= c.changed;
304362
}
305363
return changed;
@@ -395,22 +453,7 @@ public override void OnInspectorGUI()
395453
bool isGUIEnabled = !IsProfileLock((BaseMixedRealityProfile)target) && GUI.enabled;
396454
GUI.enabled = isGUIEnabled;
397455

398-
EditorGUI.BeginChangeCheck();
399456
bool changed = false;
400-
401-
// Experience configuration
402-
ExperienceScale experienceScale = (ExperienceScale)targetExperienceScale.intValue;
403-
EditorGUILayout.PropertyField(targetExperienceScale, TargetScaleContent);
404-
405-
string scaleDescription = GetExperienceDescription(experienceScale);
406-
if (!string.IsNullOrEmpty(scaleDescription))
407-
{
408-
EditorGUILayout.HelpBox(scaleDescription, MessageType.None);
409-
EditorGUILayout.Space();
410-
}
411-
412-
changed |= EditorGUI.EndChangeCheck();
413-
414457
EditorGUILayout.BeginHorizontal();
415458

416459
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/BaseEventSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public virtual void RegisterHandler<T>(IEventSystemHandler handler) where T : IE
174174
#endif
175175
Debug.Assert(typeof(T).IsAssignableFrom(handler.GetType()), "Handler passed to RegisterHandler doesn't implement a type given as generic parameter.");
176176

177-
DebugUtilities.LogVerboseFormat("Registering handler {0} against system {1}", handler, this);
177+
DebugUtilities.LogVerboseFormat("Registering handler {0} against system {1}", handler.ToString().Trim(), this);
178178

179179
TraverseEventSystemHandlerHierarchy<T>(handler, RegisterHandler);
180180
}

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)