/// <summary> /// When a controller is lost, the model is destroyed and the controller object /// is removed from the tracking dictionary. /// </summary> /// <param name="obj">The source event args to be used to determine the controller model to be removed.</param> private void InteractionManager_InteractionSourceLost(InteractionSourceLostEventArgs obj) { InteractionSource source = obj.state.source; if (source.kind == InteractionSourceKind.Controller) { MotionControllerInfo controllerInfo; if (controllerDictionary != null && controllerDictionary.TryGetValue(GenerateKey(source), out controllerInfo)) { if (OnControllerModelUnloaded != null) { OnControllerModelUnloaded(controllerInfo); } if (controllerInfo.Handedness == InteractionSourceHandedness.Left) { leftControllerModel = null; } else if (controllerInfo.Handedness == InteractionSourceHandedness.Right) { rightControllerModel = null; } controllerInfo.ControllerParent.SetActive(false); } } }
private void StartTrackingController(InteractionSource source) { string key = GenerateKey(source); MotionControllerInfo controllerInfo; if (source.kind == InteractionSourceKind.Controller) { if (!controllerDictionary.ContainsKey(key) && !loadingControllers.Contains(key)) { StartCoroutine(LoadControllerModel(source)); } else if (controllerDictionary.TryGetValue(key, out controllerInfo)) { if (controllerInfo.Handedness == InteractionSourceHandedness.Left) { leftControllerModel = controllerInfo; } else if (controllerInfo.Handedness == InteractionSourceHandedness.Right) { rightControllerModel = controllerInfo; } controllerInfo.ControllerParent.SetActive(true); if (OnControllerModelLoaded != null) { OnControllerModelLoaded(controllerInfo); } } } }
public bool TryGetControllerModel(InteractionSourceHandedness handedness, out MotionControllerInfo controller) { if (handedness == InteractionSourceHandedness.Left && leftControllerModel != null) { controller = leftControllerModel; return(true); } else if (handedness == InteractionSourceHandedness.Right && rightControllerModel != null) { controller = rightControllerModel; return(true); } else { controller = null; return(false); } }
private void FinishControllerSetup(GameObject controllerModelGameObject, InteractionSourceHandedness handedness, string dictionaryKey) { string parentGameObjectName = handedness + "ControllerModel"; // Find child with proper name - Name cannot be changed! GameObject parentGameObject = transform.Find("Controller (" + handedness.ToString() + ")/" + parentGameObjectName).gameObject; // if no child, simply create new one if (parentGameObject == null) { parentGameObject = new GameObject { name = parentGameObjectName }; parentGameObject.transform.parent = transform; } controllerModelGameObject.transform.parent = parentGameObject.transform; controllerModelGameObject.transform.localPosition = Vector3.zero; controllerModelGameObject.transform.localRotation = Quaternion.identity; var newControllerInfo = new MotionControllerInfo(parentGameObject, handedness); newControllerInfo.LoadInfo(controllerModelGameObject.GetComponentsInChildren <Transform>()); if (handedness == InteractionSourceHandedness.Left) { leftControllerModel = newControllerInfo; } else if (handedness == InteractionSourceHandedness.Right) { rightControllerModel = newControllerInfo; } if (OnControllerModelLoaded != null) { OnControllerModelLoaded(newControllerInfo); } loadingControllers.Remove(dictionaryKey); controllerDictionary.Add(dictionaryKey, newControllerInfo); }