Skip to content

Commit

Permalink
Don't save the alternate model if it's not wanted
Browse files Browse the repository at this point in the history
  • Loading branch information
keveleigh committed Nov 21, 2018
1 parent b80ff70 commit 55f8668
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class MotionControllerVisualizer : Singleton<MotionControllerVisualizer>

public event Action<MotionControllerInfo> OnControllerModelLoaded;
public event Action<MotionControllerInfo> OnControllerModelUnloaded;

private bool leftModelIsAlternate = false;
private bool rightModelIsAlternate = false;
#endif

#if UNITY_EDITOR_WIN
Expand Down Expand Up @@ -246,7 +249,8 @@ private void InteractionManager_InteractionSourceLost(InteractionSourceLostEvent
if (source.kind == InteractionSourceKind.Controller)
{
MotionControllerInfo controllerInfo;
if (controllerDictionary != null && controllerDictionary.TryGetValue(GenerateKey(source), out controllerInfo))
string key = GenerateKey(source);
if (controllerDictionary != null && controllerDictionary.TryGetValue(key, out controllerInfo))
{
if (OnControllerModelUnloaded != null)
{
Expand All @@ -256,10 +260,22 @@ private void InteractionManager_InteractionSourceLost(InteractionSourceLostEvent
if (controllerInfo.Handedness == InteractionSourceHandedness.Left)
{
leftControllerModel = null;

if (!AlwaysUseAlternateLeftModel && leftModelIsAlternate)
{
controllerDictionary.Remove(key);
Destroy(controllerInfo.ControllerParent);
}
}
else if (controllerInfo.Handedness == InteractionSourceHandedness.Right)
{
rightControllerModel = null;

if (!AlwaysUseAlternateRightModel && rightModelIsAlternate)
{
controllerDictionary.Remove(key);
Destroy(controllerInfo.ControllerParent);
}
}

controllerInfo.ControllerParent.SetActive(false);
Expand Down Expand Up @@ -390,6 +406,15 @@ private IEnumerator LoadSourceControllerModel(InteractionSource source)

yield return sceneImporter.Load();

if (source.handedness == InteractionSourceHandedness.Left)
{
leftModelIsAlternate = false;
}
else if (source.handedness == InteractionSourceHandedness.Right)
{
rightModelIsAlternate = false;
}

FinishControllerSetup(controllerModelGameObject, source.handedness, GenerateKey(source));
}

Expand All @@ -399,10 +424,12 @@ private void LoadAlternateControllerModel(InteractionSource source)
if (source.handedness == InteractionSourceHandedness.Left && AlternateLeftController != null)
{
controllerModelGameObject = Instantiate(AlternateLeftController);
leftModelIsAlternate = true;
}
else if (source.handedness == InteractionSourceHandedness.Right && AlternateRightController != null)
{
controllerModelGameObject = Instantiate(AlternateRightController);
rightModelIsAlternate = true;
}
else
{
Expand Down

0 comments on commit 55f8668

Please sign in to comment.