@@ -62,6 +62,9 @@ public class MotionControllerVisualizer : Singleton<MotionControllerVisualizer>
6262
6363 public event Action < MotionControllerInfo > OnControllerModelLoaded ;
6464 public event Action < MotionControllerInfo > OnControllerModelUnloaded ;
65+
66+ private bool leftModelIsAlternate = false ;
67+ private bool rightModelIsAlternate = false ;
6568#endif
6669
6770#if UNITY_EDITOR_WIN
@@ -246,7 +249,8 @@ private void InteractionManager_InteractionSourceLost(InteractionSourceLostEvent
246249 if ( source . kind == InteractionSourceKind . Controller )
247250 {
248251 MotionControllerInfo controllerInfo ;
249- if ( controllerDictionary != null && controllerDictionary . TryGetValue ( GenerateKey ( source ) , out controllerInfo ) )
252+ string key = GenerateKey ( source ) ;
253+ if ( controllerDictionary != null && controllerDictionary . TryGetValue ( key , out controllerInfo ) )
250254 {
251255 if ( OnControllerModelUnloaded != null )
252256 {
@@ -256,10 +260,22 @@ private void InteractionManager_InteractionSourceLost(InteractionSourceLostEvent
256260 if ( controllerInfo . Handedness == InteractionSourceHandedness . Left )
257261 {
258262 leftControllerModel = null ;
263+
264+ if ( ! AlwaysUseAlternateLeftModel && leftModelIsAlternate )
265+ {
266+ controllerDictionary . Remove ( key ) ;
267+ Destroy ( controllerInfo . ControllerParent ) ;
268+ }
259269 }
260270 else if ( controllerInfo . Handedness == InteractionSourceHandedness . Right )
261271 {
262272 rightControllerModel = null ;
273+
274+ if ( ! AlwaysUseAlternateRightModel && rightModelIsAlternate )
275+ {
276+ controllerDictionary . Remove ( key ) ;
277+ Destroy ( controllerInfo . ControllerParent ) ;
278+ }
263279 }
264280
265281 controllerInfo . ControllerParent . SetActive ( false ) ;
@@ -390,6 +406,15 @@ private IEnumerator LoadSourceControllerModel(InteractionSource source)
390406
391407 yield return sceneImporter . Load ( ) ;
392408
409+ if ( source . handedness == InteractionSourceHandedness . Left )
410+ {
411+ leftModelIsAlternate = false ;
412+ }
413+ else if ( source . handedness == InteractionSourceHandedness . Right )
414+ {
415+ rightModelIsAlternate = false ;
416+ }
417+
393418 FinishControllerSetup ( controllerModelGameObject , source . handedness , GenerateKey ( source ) ) ;
394419 }
395420
@@ -399,10 +424,12 @@ private void LoadAlternateControllerModel(InteractionSource source)
399424 if ( source . handedness == InteractionSourceHandedness . Left && AlternateLeftController != null )
400425 {
401426 controllerModelGameObject = Instantiate ( AlternateLeftController ) ;
427+ leftModelIsAlternate = true ;
402428 }
403429 else if ( source . handedness == InteractionSourceHandedness . Right && AlternateRightController != null )
404430 {
405431 controllerModelGameObject = Instantiate ( AlternateRightController ) ;
432+ rightModelIsAlternate = true ;
406433 }
407434 else
408435 {
0 commit comments