Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

No longer require the service locator to configure profiles #157

Merged
merged 1 commit into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Submodules/SDK
Submodule SDK updated from bff35f to 774b53
2 changes: 1 addition & 1 deletion Submodules/WindowsMixedReality
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,17 @@ public abstract class BaseMixedRealityProfile : ScriptableObject
private bool isCustomProfile = true;

internal bool IsCustomProfile => isCustomProfile;

[SerializeField]
private BaseMixedRealityProfile parentProfile = null;

/// <summary>
/// The profile's parent.
/// </summary>
public BaseMixedRealityProfile ParentProfile
{
get => parentProfile;
internal set => parentProfile = value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,13 @@ public static class ControllerMappingLibrary
/// <summary>
/// Gets a texture for the <see cref="SupportedControllerType"/> based on a list of the active <see cref="MixedRealityControllerMappingProfiles"/>.
/// </summary>
/// <param name="mappingProfile"></param>
/// <param name="controllerType"></param>
/// <param name="handedness"></param>
/// <returns>The texture for the controller type, if none found then a generic texture is returned.</returns>
public static Texture2D GetControllerTexture(SupportedControllerType controllerType, Handedness handedness)
public static Texture2D GetControllerTexture(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness)
{
return GetControllerTextureCached(controllerType, handedness);
return GetControllerTextureCached(mappingProfile, controllerType, handedness);
}

/// <summary>
Expand All @@ -252,44 +253,35 @@ public static Texture2D GetControllerTexture(SupportedControllerType controllerT
/// <param name="controllerType"></param>
/// <param name="handedness"></param>
/// <returns>The scaled texture for the controller type, if none found then a generic texture is returned.</returns>
public static Texture2D GetControllerTextureScaled(SupportedControllerType controllerType, Handedness handedness)
public static Texture2D GetControllerTextureScaled(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness)
{
return GetControllerTextureCached(controllerType, handedness, true);
return GetControllerTextureCached(mappingProfile, controllerType, handedness, true);
}

private static Texture2D GetControllerTextureCached(SupportedControllerType controllerType, Handedness handedness, bool scaled = false)
private static Texture2D GetControllerTextureCached(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness, bool scaled = false)
{
var key = new Tuple<SupportedControllerType, Handedness, bool>(controllerType, handedness, scaled);

if (CachedTextures.TryGetValue(key, out Texture2D texture))
if (CachedTextures.TryGetValue(key, out var texture))
{
return texture;
}

texture = GetControllerTextureInternal(controllerType, handedness, scaled);
texture = GetControllerTextureInternal(mappingProfile, controllerType, handedness, scaled);
CachedTextures.Add(key, texture);
return texture;
}

private static Texture2D GetControllerTextureInternal(SupportedControllerType controllerType, Handedness handedness, bool scaled)
private static Texture2D GetControllerTextureInternal(BaseMixedRealityControllerMappingProfile mappingProfile, SupportedControllerType controllerType, Handedness handedness, bool scaled)
{
var profiles = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.ControllerMappingProfiles;

if (MixedRealityToolkit.Instance.ActiveProfile.IsInputSystemEnabled &&
profiles != null)
if (mappingProfile != null &&
mappingProfile.ControllerType == controllerType)
{
foreach (var profile in profiles.ControllerMappingProfiles)
var texture = GetControllerTextureInternal(mappingProfile.TexturePath, handedness, scaled);

if (texture != null)
{
if (profile != null &&
profile.ControllerType == controllerType)
{
var texture = GetControllerTextureInternal(profile.TexturePath, handedness, scaled);

if (texture != null)
{
return texture;
}
}
return texture;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
using XRTK.Definitions.InputSystem;
using XRTK.Definitions.Utilities;
using XRTK.Inspectors.Data;
using XRTK.Inspectors.Profiles;
using XRTK.Inspectors.Utilities;
using XRTK.Providers.Controllers;
using XRTK.Services;
using XRTK.Utilities.Editor;

Expand Down Expand Up @@ -92,110 +94,113 @@ public class ControllerPopupWindow : EditorWindow
private Texture2D currentControllerTexture;
private ControllerInputActionOption currentControllerOption;

private MixedRealityInputSystemProfile inputSystemProfile;
private static BaseMixedRealityControllerMappingProfile mappingProfile;

private bool IsCustomController => currentControllerType == SupportedControllerType.GenericOpenVR ||
currentControllerType == SupportedControllerType.GenericUnity;
private static string EditorWindowOptionsPath => $"{MixedRealityEditorSettings.MixedRealityToolkit_RelativeFolderPath}/Inspectors/Data/EditorWindowOptions.json";

private void OnFocus()
{
currentControllerTexture = ControllerMappingLibrary.GetControllerTexture(currentControllerType, currentHandedness);
currentControllerTexture = ControllerMappingLibrary.GetControllerTexture(mappingProfile, currentControllerType, currentHandedness);
inputSystemProfile = mappingProfile.ParentProfile.ParentProfile as MixedRealityInputSystemProfile;

#region Interaction Constraint Setup

actionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions

actionIds = inputSystemProfile.InputActionsProfile.InputActions
.Select(action => (int)action.Id)
.Prepend(0).ToArray();

axisLabels = ControllerMappingLibrary.UnityInputManagerAxes
.Select(axis => new GUIContent(axis.Name))
.Prepend(new GUIContent("None")).ToArray();

actionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
actionIds = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.None)
.Select(action => (int)action.Id)
.Prepend(0).ToArray();

actionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
actionLabels = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.None)
.Select(inputAction => new GUIContent(inputAction.Description))
.Prepend(new GUIContent("None")).ToArray();

rawActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
rawActionIds = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.Raw)
.Select(action => (int)action.Id)
.Prepend(0).ToArray();

rawActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
rawActionLabels = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.Raw)
.Select(inputAction => new GUIContent(inputAction.Description))
.Prepend(new GUIContent("None")).ToArray();

digitalActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
digitalActionIds = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.Digital)
.Select(action => (int)action.Id)
.Prepend(0).ToArray();

digitalActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
digitalActionLabels = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.Digital)
.Select(inputAction => new GUIContent(inputAction.Description))
.Prepend(new GUIContent("None")).ToArray();

singleAxisActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
singleAxisActionIds = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.SingleAxis)
.Select(action => (int)action.Id)
.Prepend(0).ToArray();

singleAxisActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
singleAxisActionLabels = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.SingleAxis)
.Select(inputAction => new GUIContent(inputAction.Description))
.Prepend(new GUIContent("None")).ToArray();

dualAxisActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
dualAxisActionIds = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.DualAxis)
.Select(action => (int)action.Id).Prepend(0).ToArray();

dualAxisActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
dualAxisActionLabels = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.DualAxis)
.Select(inputAction => new GUIContent(inputAction.Description))
.Prepend(new GUIContent("None")).ToArray();

threeDofPositionActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
threeDofPositionActionIds = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofPosition)
.Select(action => (int)action.Id)
.Prepend(0).ToArray();

threeDofPositionActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
threeDofPositionActionLabels = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofPosition)
.Select(inputAction => new GUIContent(inputAction.Description))
.Prepend(new GUIContent("None")).ToArray();

threeDofRotationActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
threeDofRotationActionIds = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofRotation)
.Select(action => (int)action.Id)
.Prepend(0).ToArray();

threeDofRotationActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
threeDofRotationActionLabels = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.ThreeDofRotation)
.Select(inputAction => new GUIContent(inputAction.Description))
.Prepend(new GUIContent("None")).ToArray();

sixDofActionIds = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
sixDofActionIds = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.SixDof)
.Select(action => (int)action.Id)
.Prepend(0).ToArray();

sixDofActionLabels = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions
sixDofActionLabels = inputSystemProfile.InputActionsProfile.InputActions
.Where(inputAction => inputAction.AxisConstraint == AxisType.SixDof)
.Select(inputAction => new GUIContent(inputAction.Description))
.Prepend(new GUIContent("None")).ToArray();

#endregion Interaction Constraint Setup
}

public static void Show(SupportedControllerType controllerType, SerializedProperty interactionsList, Handedness handedness = Handedness.None, bool isLocked = false)
public static void Show(BaseMixedRealityControllerMappingProfile profile, SupportedControllerType controllerType, SerializedProperty interactionsList, Handedness handedness = Handedness.None, bool isLocked = false)
{
window = (ControllerPopupWindow)GetWindow(typeof(ControllerPopupWindow));
window.Close();
window = (ControllerPopupWindow)CreateInstance(typeof(ControllerPopupWindow));
var handednessTitleText = handedness != Handedness.None ? $"{handedness} Hand " : string.Empty;
window.titleContent = new GUIContent($"{controllerType} {handednessTitleText}Input Action Assignment");
Expand All @@ -204,7 +209,7 @@ public static void Show(SupportedControllerType controllerType, SerializedProper
window.isLocked = isLocked;
window.currentInteractionList = interactionsList;
isMouseInRects = new bool[interactionsList.arraySize];

mappingProfile = profile;
var asset = AssetDatabase.LoadAssetAtPath<TextAsset>(EditorWindowOptionsPath);

if (asset == null)
Expand Down Expand Up @@ -492,7 +497,7 @@ private void RenderInteractionList(SerializedProperty interactionList, bool useC

if (EditorGUI.EndChangeCheck())
{
var inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
var inputAction = actionId.intValue == 0 ? MixedRealityInputAction.None : inputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
actionDescription.stringValue = inputAction.Description;
actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint;
}
Expand Down Expand Up @@ -732,7 +737,7 @@ private void RenderInteractionList(SerializedProperty interactionList, bool useC
{
MixedRealityInputAction inputAction = actionId.intValue == 0 ?
MixedRealityInputAction.None :
MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
inputSystemProfile.InputActionsProfile.InputActions[actionId.intValue - 1];
actionId.intValue = (int)inputAction.Id;
actionDescription.stringValue = inputAction.Description;
actionConstraint.enumValueIndex = (int)inputAction.AxisConstraint;
Expand Down
Loading