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

Commit

Permalink
Added IMixedRealityController.Name (#589)
Browse files Browse the repository at this point in the history
Better logging when mapping profiles are empty
  • Loading branch information
StephenHodgson authored May 17, 2020
1 parent c7f1f88 commit e7abe8a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ namespace XRTK.Interfaces.Providers.Controllers
/// </summary>
public interface IMixedRealityController
{
/// <summary>
/// The name of the controller.
/// </summary>
string Name { get; }

/// <summary>
/// Is the controller enabled?
/// </summary>
Expand Down
17 changes: 11 additions & 6 deletions Runtime/Providers/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ protected BaseController() { }
/// <param name="controllerMappingProfile"></param>
protected BaseController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile)
{
if (controllerMappingProfile == null)
{
throw new Exception($"{nameof(controllerMappingProfile)} cannot be null");
}

ControllerDataProvider = controllerDataProvider;
TrackingState = trackingState;
ControllerHandedness = controllerHandedness;
Expand All @@ -56,6 +51,13 @@ protected BaseController(IMixedRealityControllerDataProvider controllerDataProvi
handednessPrefix = $"{controllerHandedness} ";
}

Name = $"{handednessPrefix}{GetType().Name}";

if (controllerMappingProfile == null)
{
throw new Exception($"{nameof(controllerMappingProfile)} cannot be null for {Name}");
}

visualizationProfile = controllerMappingProfile.VisualizationProfile;
var pointers = AssignControllerMappings(controllerMappingProfile.InteractionMappingProfiles);

Expand All @@ -65,7 +67,7 @@ protected BaseController(IMixedRealityControllerDataProvider controllerDataProvi
throw new Exception($"No Controller interaction mappings found for {controllerMappingProfile.name}!");
}

InputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"{handednessPrefix}{GetType().Name}", pointers);
InputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource(Name, pointers);

for (int i = 0; i < InputSource?.Pointers?.Length; i++)
{
Expand Down Expand Up @@ -98,6 +100,9 @@ protected BaseController(IMixedRealityControllerDataProvider controllerDataProvi

#region IMixedRealityController Implementation

/// <inheritdoc />
public string Name { get; }

/// <inheritdoc />
public bool Enabled { get; set; }

Expand Down
7 changes: 7 additions & 0 deletions Runtime/Providers/Controllers/BaseControllerDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ protected BaseControllerDataProvider(string name, uint priority, BaseMixedRealit
}

controllerMappingProfiles = profile.ControllerMappingProfiles;

if (controllerMappingProfiles == null ||
controllerMappingProfiles.Length == 0)
{
throw new UnassignedReferenceException($"{nameof(controllerMappingProfiles)} has no defined controller mappings for {name}");
}
}

private readonly MixedRealityControllerMappingProfile[] controllerMappingProfiles;
Expand Down Expand Up @@ -62,6 +68,7 @@ public MixedRealityControllerMappingProfile GetControllerMappingProfile(Type con
}
}

Debug.LogError($"Failed to find a controller mapping for {controllerType.Name} with with handedness: {handedness}");
return null;
}

Expand Down

0 comments on commit e7abe8a

Please sign in to comment.