public IEnumerator TestProfileContentOffset() { float contentOffset = 3.0f; var hl1Profile = ScriptableObjectExtensions.GetAllInstances <MixedRealityToolkitConfigurationProfile>() .FirstOrDefault(x => x.name.Equals(HoloLens1ProfileName)); // keep the old floor height and experience scale to reset it later ExperienceScale originalExperienceScale = hl1Profile.ExperienceSettingsProfile.TargetExperienceScale; float oldContentOffset = hl1Profile.ExperienceSettingsProfile.ContentOffset; hl1Profile.ExperienceSettingsProfile.TargetExperienceScale = ExperienceScale.Room; hl1Profile.ExperienceSettingsProfile.ContentOffset = contentOffset; TestUtilities.InitializeMixedRealityToolkit(hl1Profile); TestUtilities.InitializeCamera(); yield return(new WaitForSeconds(0.5f)); MixedRealitySceneContent sceneContent = GameObject.Find("MixedRealitySceneContent").GetComponent <MixedRealitySceneContent>(); TestUtilities.AssertAboutEqual(TestUtilities.PositionRelativeToPlayspace(Vector3.zero), Vector3.zero, "The playspace was not set to the origin"); TestUtilities.AssertAboutEqual(sceneContent.transform.position, Vector3.up * contentOffset, "The floor height was not set correctly"); // be sure to set the profile's ContentOffset back to it's original value afterwards hl1Profile.ExperienceSettingsProfile.TargetExperienceScale = originalExperienceScale; hl1Profile.ExperienceSettingsProfile.ContentOffset = oldContentOffset; TestUtilities.InitializeMixedRealityToolkit(hl1Profile); }
public static T GetDefaultMixedRealityProfile <T>() where T : BaseMixedRealityProfile { #if UNITY_EDITOR return(ScriptableObjectExtensions.GetAllInstances <T>().FirstOrDefault(profile => profile.name.Equals($"Default{typeof(T).Name}"))); #else return(ScriptableObject.CreateInstance <T>()); #endif }
public IEnumerator Setup() { var riggedHandProfile = ScriptableObjectExtensions.GetAllInstances <MixedRealityToolkitConfigurationProfile>() .FirstOrDefault(x => x.name.Equals(RiggedHandProfileName)); PlayModeTestUtilities.Setup(riggedHandProfile); yield return(null); }
/// <summary> /// Returns an array of profiles that match profile type. /// </summary> public static ScriptableObject[] GetProfilesOfType(Type profileType) { ScriptableObject[] profilesOfType = null; if (!profileCaches.TryGetValue(profileType, out profilesOfType)) { profilesOfType = ScriptableObjectExtensions.GetAllInstances(profileType); profileCaches.Add(profileType, profilesOfType); } return(profilesOfType); }
private static void RefreshProfileCaches() { List <Type> cachedTypes = new List <Type>(profileCaches.Keys); profileContentCaches.Clear(); foreach (Type profileType in cachedTypes) { profileCaches[profileType] = ScriptableObjectExtensions.GetAllInstances(profileType); } }
protected override void OnEnable() { base.OnEnable(); keywords = serializedObject.FindProperty(nameof(keywords)); persistentKeywords = serializedObject.FindProperty(nameof(persistentKeywords)); var profiles = ScriptableObjectExtensions.GetAllInstances <MixedRealitySpeechCommandsProfile>(); registeredKeywords = RegisteredKeywords(profiles).Distinct().ToArray(); }
/// <summary> /// Generates an interactable from primitives and assigns a select action. /// </summary> /// <param name="interactableObject"></param> /// <param name="interactable"></param> /// <param name="translateTargetObject"></param> /// <param name="selectActionDescription"></param> private void AssembleInteractableButton(out GameObject interactableObject, out Interactable interactable, out Transform translateTargetObject, string selectActionDescription = "Select") { // Assemble an interactable out of a set of primitives // This will be the button housing interactableObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder); interactableObject.name = "RuntimeInteractable"; interactableObject.transform.position = new Vector3(0.05f, 0.05f, 0.625f); interactableObject.transform.localScale = new Vector3(0.15f, 0.025f, 0.15f); interactableObject.transform.eulerAngles = new Vector3(90f, 0f, 180f); // This will be the part that gets scaled GameObject childObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder); childObject.GetComponent <Renderer>().material.color = Color.blue; childObject.transform.parent = interactableObject.transform; childObject.transform.localScale = new Vector3(0.9f, 1f, 0.9f); childObject.transform.localPosition = new Vector3(0f, 1.5f, 0f); childObject.transform.localRotation = Quaternion.identity; // Only use a collider on the main object GameObject.Destroy(childObject.GetComponent <Collider>()); translateTargetObject = childObject.transform; // Add an interactable interactable = interactableObject.AddComponent <Interactable>(); #if UNITY_EDITOR // Find our states and themes via the asset database Theme cylinderTheme = ScriptableObjectExtensions.GetAllInstances <Theme>().FirstOrDefault(profile => profile.name.Equals($"CylinderTheme")); States defaultStates = ScriptableObjectExtensions.GetAllInstances <States>().FirstOrDefault(profile => profile.name.Equals($"DefaultInteractableStates")); interactable.States = defaultStates; InteractableProfileItem profileItem = new InteractableProfileItem(); profileItem.Themes = new System.Collections.Generic.List <Theme>() { cylinderTheme }; profileItem.HadDefaultTheme = true; profileItem.Target = translateTargetObject.gameObject; interactable.Profiles = new System.Collections.Generic.List <InteractableProfileItem>() { profileItem }; interactable.ForceUpdateThemes(); #endif // Set the interactable to respond to the requested input action MixedRealityInputAction selectAction = MixedRealityToolkit.InputSystem.InputSystemProfile.InputActionsProfile.InputActions.Where(m => m.Description == selectActionDescription).FirstOrDefault(); Assert.NotNull(selectAction.Description, "Couldn't find " + selectActionDescription + " input action in input system profile."); interactable.InputAction = selectAction; }
public IEnumerator TestHL1Profile() { var hl1Profile = ScriptableObjectExtensions.GetAllInstances <MixedRealityToolkitConfigurationProfile>() .FirstOrDefault(x => x.name.Equals(HoloLens1ProfileName)); TestUtilities.InitializeMixedRealityToolkit(hl1Profile); TestHand hand = new TestHand(Handedness.Right); yield return(hand.Show(Vector3.forward)); var allPointers = GetAllPointers(); // https://nunit.org/docs/2.5.5/collectionConstraints.html Assert.That(allPointers, Has.Some.InstanceOf(typeof(GGVPointer))); Assert.That(allPointers, Has.No.InstanceOf(typeof(ShellHandRayPointer))); }
private static void AddConfigurations(List <string> profiles) { MixedRealityToolkitRootProfile rootProfile; if (MixedRealityToolkit.IsInitialized) { rootProfile = MixedRealityToolkit.Instance.ActiveProfile; } else { var availableRootProfiles = ScriptableObjectExtensions.GetAllInstances <MixedRealityToolkitRootProfile>(); rootProfile = availableRootProfiles.Length > 0 ? availableRootProfiles[0] : null; } // Only if a root profile is available at all it makes sense to display the // platform configuration import dialog. If the user does not have a root profile yet, // for whatever reason, there is nothing we can do here. if (rootProfile.IsNull()) { EditorUtility.DisplayDialog("Attention!", "Each data provider will need to be manually registered in each service configuration.", "OK"); return; } Selection.activeObject = null; foreach (var profile in profiles.Where(x => x.EndsWith(".asset"))) { var platformConfigurationProfile = AssetDatabase.LoadAssetAtPath <MixedRealityPlatformServiceConfigurationProfile>(profile); if (platformConfigurationProfile.IsNull()) { continue; } if (EditorUtility.DisplayDialog("We found a new Platform Configuration", $"We found the {platformConfigurationProfile.name.ToProperCase()}. Would you like to add this platform configuration to your {nameof(MixedRealityToolkitRootProfile)}?", "Yes, Absolutely!", "later")) { InstallConfiguration(platformConfigurationProfile, rootProfile); } } }
/// <summary> /// Returns the default config profile, if it exists. /// </summary> public static MixedRealityToolkitConfigurationProfile GetDefaultConfigProfile() { var allConfigProfiles = ScriptableObjectExtensions.GetAllInstances<MixedRealityToolkitConfigurationProfile>(); return GetDefaultConfigProfile(allConfigProfiles); }
public void OnGui(Rect rect, SerializedProperty property, GUIContent content, AxisType axisConstraintFilter = AxisType.None) { var label = EditorGUI.BeginProperty(rect, content, property); var id = property.FindPropertyRelative("id"); var profileGuid = property.FindPropertyRelative("profileGuid"); var description = property.FindPropertyRelative("description"); var axisConstraint = property.FindPropertyRelative("axisConstraint"); if (string.IsNullOrWhiteSpace(profileGuid.stringValue)) { profileGuid.stringValue = DefaultGuidString; } var currentAction = new MixedRealityInputAction(Guid.Parse(profileGuid.stringValue), (uint)id.intValue, description.stringValue, (AxisType)axisConstraint.intValue); if (allInputActionProfiles == null) { allInputActionProfiles = ScriptableObjectExtensions.GetAllInstances <MixedRealityInputActionsProfile>(); } var dropdownMenu = new GenericMenu { allowDuplicateNames = true }; dropdownMenu.AddItem(new GUIContent("None"), false, data => ResetAction(), null); foreach (var inputActionProfile in allInputActionProfiles) { dropdownMenu.AddSeparator($"{inputActionProfile.name}/"); foreach (var inputAction in inputActionProfile.InputActions) { if (axisConstraintFilter != AxisType.None && axisConstraintFilter != inputAction.AxisConstraint) { if (inputAction == currentAction) { ResetAction(); } continue; } dropdownMenu.AddItem( new GUIContent($"{inputActionProfile.name}/{inputAction.Description}"), inputAction == currentAction, OnItemSelect, null); void OnItemSelect(object _) { id.intValue = (int)inputAction.Id; description.stringValue = inputAction.Description; axisConstraint.intValue = (int)inputAction.AxisConstraint; profileGuid.stringValue = inputAction.ProfileGuid.ToString("N"); property.serializedObject.ApplyModifiedProperties(); GUI.changed = true; } } } void ResetAction() { id.intValue = 0; description.stringValue = "None"; axisConstraint.intValue = 0; profileGuid.stringValue = DefaultGuidString; property.serializedObject.ApplyModifiedProperties(); GUI.changed = true; } var prefix = EditorGUI.PrefixLabel(rect, label); if (EditorGUI.DropdownButton(prefix, new GUIContent(description.stringValue), FocusType.Passive)) { dropdownMenu.DropDown(prefix); } EditorGUI.EndProperty(); }
public override void OnInspectorGUI() { MixedRealityInspectorUtility.RenderMixedRealityToolkitLogo(); serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField(new GUIContent("Mixed Reality Toolkit Root Profile", "This profile is the main root configuration for the entire XRTK.")); if (activeProfile.objectReferenceValue != null) { EditorGUILayout.PropertyField(activeProfile, GUIContent.none); } else { if (GUILayout.Button("Create a new root profile")) { var rootProfile = CreateInstance <MixedRealityToolkitRootProfile>().GetOrCreateAsset(); activeProfile.objectReferenceValue = rootProfile; } } var changed = EditorGUI.EndChangeCheck(); var commandName = Event.current.commandName; var rootProfiles = ScriptableObjectExtensions.GetAllInstances <MixedRealityToolkitRootProfile>(); if (activeProfile.objectReferenceValue.IsNull() && currentPickerWindow == -1 && checkChange) { switch (rootProfiles.Length) { case 0: EditorGUIUtility.PingObject(target); EditorUtility.DisplayDialog("Attention!", "No root profile for the Mixed Reality Toolkit was found.\n\nYou'll need to create a new one.", "OK"); break; case 1: var rootProfilePath = AssetDatabase.GetAssetPath(rootProfiles[0]); EditorApplication.delayCall += () => { changed = true; var rootProfile = AssetDatabase.LoadAssetAtPath <MixedRealityToolkitRootProfile>(rootProfilePath); Debug.Assert(rootProfile != null); activeProfile.objectReferenceValue = rootProfile; EditorGUIUtility.PingObject(rootProfile); Selection.activeObject = rootProfile; MixedRealityToolkit.Instance.ResetProfile(rootProfile); }; break; default: EditorUtility.DisplayDialog("Attention!", "You must choose a profile for the Mixed Reality Toolkit.", "OK"); currentPickerWindow = GUIUtility.GetControlID(FocusType.Passive); EditorGUIUtility.ShowObjectPicker <MixedRealityToolkitRootProfile>(null, false, string.Empty, currentPickerWindow); break; } checkChange = false; } if (EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow) { switch (commandName) { case "ObjectSelectorUpdated": activeProfile.objectReferenceValue = EditorGUIUtility.GetObjectPickerObject(); changed = true; break; case "ObjectSelectorClosed": activeProfile.objectReferenceValue = EditorGUIUtility.GetObjectPickerObject(); currentPickerWindow = -1; changed = true; EditorApplication.delayCall += () => { EditorGUIUtility.PingObject(activeProfile.objectReferenceValue); Selection.activeObject = activeProfile.objectReferenceValue; }; break; } } if (activeProfile.objectReferenceValue != null) { var rootProfile = activeProfile.objectReferenceValue as MixedRealityToolkitRootProfile; var profileInspector = CreateEditor(rootProfile); if (profileInspector is MixedRealityToolkitRootProfileInspector rootProfileInspector) { EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); Rect rect = new Rect(GUILayoutUtility.GetLastRect()) { height = 0.75f }; EditorGUI.DrawRect(rect, Color.gray); EditorGUILayout.Space(); rootProfileInspector.RenderSystemFields(); } } serializedObject.ApplyModifiedProperties(); if (changed) { EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetProfile((MixedRealityToolkitRootProfile)activeProfile.objectReferenceValue); } }
public static T GetDefaultMixedRealityProfile <T>() where T : BaseMixedRealityProfile { return(ScriptableObjectExtensions.GetAllInstances <T>().FirstOrDefault(profile => profile.name.Equals($"Default{typeof(T).Name}"))); }
public override void OnInspectorGUI() { RenderMixedRealityToolkitLogo(); serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(activeProfile); var changed = EditorGUI.EndChangeCheck(); var commandName = Event.current.commandName; var allConfigProfiles = ScriptableObjectExtensions.GetAllInstances <MixedRealityToolkitConfigurationProfile>(); if (activeProfile.objectReferenceValue == null) { if (currentPickerWindow == -1 && checkChange) { if (allConfigProfiles.Length > 1) { EditorUtility.DisplayDialog("Attention!", "You must choose a profile for the Mixed Reality Toolkit.", "OK"); currentPickerWindow = GUIUtility.GetControlID(FocusType.Passive); EditorGUIUtility.ShowObjectPicker <MixedRealityToolkitConfigurationProfile>(GetDefaultProfile(allConfigProfiles), false, string.Empty, currentPickerWindow); } else if (allConfigProfiles.Length == 1) { activeProfile.objectReferenceValue = allConfigProfiles[0]; changed = true; Selection.activeObject = allConfigProfiles[0]; EditorGUIUtility.PingObject(allConfigProfiles[0]); } checkChange = false; } if (GUILayout.Button("Create new configuration")) { var profile = CreateInstance(nameof(MixedRealityToolkitConfigurationProfile)); profile.CreateAsset("Assets/XRTK.Generated/CustomProfiles"); activeProfile.objectReferenceValue = profile; Selection.activeObject = profile; EditorGUIUtility.PingObject(profile); } } if (EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow) { switch (commandName) { case "ObjectSelectorUpdated": activeProfile.objectReferenceValue = EditorGUIUtility.GetObjectPickerObject(); changed = true; break; case "ObjectSelectorClosed": activeProfile.objectReferenceValue = EditorGUIUtility.GetObjectPickerObject(); currentPickerWindow = -1; changed = true; Selection.activeObject = activeProfile.objectReferenceValue; EditorGUIUtility.PingObject(activeProfile.objectReferenceValue); break; } } serializedObject.ApplyModifiedProperties(); if (changed) { MixedRealityToolkit.Instance.ResetConfiguration((MixedRealityToolkitConfigurationProfile)activeProfile.objectReferenceValue); } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(activeProfile); bool changed = EditorGUI.EndChangeCheck(); string commandName = Event.current.commandName; var allConfigProfiles = ScriptableObjectExtensions.GetAllInstances <MixedRealityConfigurationProfile>(); if (activeProfile.objectReferenceValue == null && currentPickerWindow == -1 && checkChange) { if (allConfigProfiles.Length > 1) { EditorUtility.DisplayDialog("Attention!", "You must choose a profile for the Mixed Reality Manager.", "OK"); currentPickerWindow = GUIUtility.GetControlID(FocusType.Passive); EditorGUIUtility.ShowObjectPicker <MixedRealityConfigurationProfile>(null, false, string.Empty, currentPickerWindow); } else if (allConfigProfiles.Length == 1) { activeProfile.objectReferenceValue = allConfigProfiles[0]; changed = true; Selection.activeObject = allConfigProfiles[0]; EditorGUIUtility.PingObject(allConfigProfiles[0]); } else { if (EditorUtility.DisplayDialog("Attention!", "No profiles were found for the Mixed Reality Manager.\n\n" + "Would you like to create one now?", "OK", "Later")) { ScriptableObject profile = CreateInstance(nameof(MixedRealityConfigurationProfile)); profile.CreateAsset(); activeProfile.objectReferenceValue = profile; Selection.activeObject = profile; EditorGUIUtility.PingObject(profile); } } checkChange = false; } if (EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow) { switch (commandName) { case "ObjectSelectorUpdated": activeProfile.objectReferenceValue = EditorGUIUtility.GetObjectPickerObject(); changed = true; break; case "ObjectSelectorClosed": activeProfile.objectReferenceValue = EditorGUIUtility.GetObjectPickerObject(); currentPickerWindow = -1; changed = true; Selection.activeObject = activeProfile.objectReferenceValue; EditorGUIUtility.PingObject(activeProfile.objectReferenceValue); break; } } serializedObject.ApplyModifiedProperties(); if (changed) { MixedRealityManager.Instance.ResetConfiguration((MixedRealityConfigurationProfile)activeProfile.objectReferenceValue); } }