@@ -177,9 +177,8 @@ private void Initialize()
177177 Utilities . Editor . InputMappingAxisUtility . CheckUnityInputManagerMappings ( Definitions . Devices . ControllerMappingLibrary . UnityInputManagerAxes ) ;
178178#endif
179179
180- RegisterService ( typeof ( IMixedRealityInputSystem ) , Activator . CreateInstance ( ActiveProfile . InputSystemType ) as IMixedRealityInputSystem ) ;
181-
182- if ( InputSystem == null )
180+ if ( ! RegisterService ( typeof ( IMixedRealityInputSystem ) , Activator . CreateInstance ( ActiveProfile . InputSystemType ) as IMixedRealityInputSystem ) ||
181+ InputSystem == null )
183182 {
184183 Debug . LogError ( "Failed to start the Input System!" ) ;
185184 }
@@ -188,9 +187,8 @@ private void Initialize()
188187 // If the Boundary system has been selected for initialization in the Active profile, enable it in the project
189188 if ( ActiveProfile . IsBoundarySystemEnabled )
190189 {
191- RegisterService ( typeof ( IMixedRealityBoundarySystem ) , Activator . CreateInstance ( ActiveProfile . BoundarySystemSystemType ) as IMixedRealityBoundarySystem ) ;
192-
193- if ( BoundarySystem == null )
190+ if ( ! RegisterService ( typeof ( IMixedRealityBoundarySystem ) , Activator . CreateInstance ( ActiveProfile . BoundarySystemSystemType ) as IMixedRealityBoundarySystem ) ||
191+ BoundarySystem == null )
194192 {
195193 Debug . LogError ( "Failed to start the Boundary System!" ) ;
196194 }
@@ -200,19 +198,17 @@ private void Initialize()
200198 // If the Teleport system has been selected for initialization in the Active profile, enable it in the project
201199 if ( ActiveProfile . IsTeleportSystemEnabled )
202200 {
203- RegisterService ( typeof ( IMixedRealityTeleportSystem ) , Activator . CreateInstance ( ActiveProfile . TeleportSystemSystemType ) as IMixedRealityTeleportSystem ) ;
204-
205- if ( TeleportSystem == null )
201+ if ( ! RegisterService ( typeof ( IMixedRealityTeleportSystem ) , Activator . CreateInstance ( ActiveProfile . TeleportSystemSystemType ) as IMixedRealityTeleportSystem ) ||
202+ TeleportSystem == null )
206203 {
207204 Debug . LogError ( "Failed to start the Teleport System!" ) ;
208205 }
209206 }
210207
211208 if ( ActiveProfile . IsDiagnosticsSystemEnabled )
212209 {
213- RegisterService ( typeof ( IMixedRealityDiagnosticsSystem ) , Activator . CreateInstance ( ActiveProfile . DiagnosticsSystemSystemType ) as IMixedRealityDiagnosticsSystem ) ;
214-
215- if ( DiagnosticsSystem == null )
210+ if ( ! RegisterService ( typeof ( IMixedRealityDiagnosticsSystem ) , Activator . CreateInstance ( ActiveProfile . DiagnosticsSystemSystemType ) as IMixedRealityDiagnosticsSystem ) ||
211+ DiagnosticsSystem == null )
216212 {
217213 Debug . LogError ( "Failed to start the Diagnostics System!" ) ;
218214 }
@@ -231,7 +227,10 @@ private void Initialize()
231227 {
232228 if ( configuration . ComponentType . Type != null )
233229 {
234- RegisterService ( typeof ( IMixedRealityExtensionService ) , Activator . CreateInstance ( configuration . ComponentType , configuration . ComponentName , configuration . Priority ) as IMixedRealityExtensionService ) ;
230+ if ( ! RegisterService ( typeof ( IMixedRealityExtensionService ) , Activator . CreateInstance ( configuration . ComponentType , configuration . ComponentName , configuration . Priority ) as IMixedRealityExtensionService ) )
231+ {
232+ Debug . LogError ( $ "Failed to register the { configuration . ComponentType . Type } Extension Service!") ;
233+ }
235234 }
236235 }
237236 }
@@ -489,50 +488,54 @@ private void OnDestroy()
489488 /// </summary>
490489 /// <param name="type">The interface type for the system to be managed. E.G. InputSystem, BoundarySystem</param>
491490 /// <param name="service">The Instance of the service class to register</param>
492- public void RegisterService ( Type type , IMixedRealityService service )
491+ public bool RegisterService ( Type type , IMixedRealityService service )
493492 {
494493 if ( ActiveProfile == null )
495494 {
496495 Debug . LogError ( $ "Unable to add a new { type . Name } Service as the Mixed Reality Toolkit has to Active Profile") ;
496+ return false ;
497497 }
498498
499499 if ( type == null )
500500 {
501501 Debug . LogWarning ( "Unable to add a manager of type null." ) ;
502- return ;
502+ return false ;
503503 }
504504 if ( service == null )
505505 {
506506 Debug . LogWarning ( "Unable to add a manager with a null instance." ) ;
507- return ;
507+ return false ;
508508 }
509509
510510 if ( IsCoreSystem ( type ) )
511511 {
512512 IMixedRealityService preExistingService ;
513- if ( IsCoreSystem ( type ) )
514- {
515- ActiveProfile . ActiveServices . TryGetValue ( type , out preExistingService ) ;
516- }
517- else
518- {
519- GetService ( type , out preExistingService ) ;
520- }
513+
514+ ActiveProfile . ActiveServices . TryGetValue ( type , out preExistingService ) ;
521515
522516 if ( preExistingService == null )
523517 {
524518 ActiveProfile . ActiveServices . Add ( type , service ) ;
519+ return true ;
525520 }
526521 else
527522 {
528523 Debug . LogError ( $ "There's already a { type . Name } registered.") ;
524+ return false ;
529525 }
530526 }
531527 else
532528 {
529+ if ( ! typeof ( IMixedRealityExtensionService ) . IsAssignableFrom ( type ) )
530+ {
531+ Debug . LogError ( $ "Unable to register { service } . Concrete type does not implement the IMixedRealityExtensionService implementation.") ;
532+ return false ;
533+ }
534+
533535 MixedRealityComponents . Add ( new Tuple < Type , IMixedRealityExtensionService > ( type , ( IMixedRealityExtensionService ) service ) ) ;
534536 if ( ! isInitializing ) { service . Initialize ( ) ; }
535537 mixedRealityComponentsCount = MixedRealityComponents . Count ;
538+ return true ;
536539 }
537540 }
538541
@@ -1024,10 +1027,10 @@ private bool IsCoreSystem(Type type)
10241027 return false ;
10251028 }
10261029
1027- return type == typeof ( IMixedRealityInputSystem ) ||
1028- type == typeof ( IMixedRealityTeleportSystem ) ||
1029- type == typeof ( IMixedRealityBoundarySystem ) ||
1030- type == typeof ( IMixedRealityDiagnosticsSystem ) ;
1030+ return typeof ( IMixedRealityInputSystem ) . IsAssignableFrom ( type ) ||
1031+ typeof ( IMixedRealityTeleportSystem ) . IsAssignableFrom ( type ) ||
1032+ typeof ( IMixedRealityBoundarySystem ) . IsAssignableFrom ( type ) ||
1033+ typeof ( IMixedRealityDiagnosticsSystem ) . IsAssignableFrom ( type ) ;
10311034 }
10321035
10331036 /// <summary>
0 commit comments