private void FinishControllerSetup(GameObject controllerModelGameObject, InteractionSourceHandedness handedness, string dictionaryKey) { var parentGameObject = new GameObject { name = handedness + "Controller" }; parentGameObject.transform.parent = transform; controllerModelGameObject.transform.parent = parentGameObject.transform; 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); }
/// <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); } } } }
private IEnumerator Attach(GameObject target, Transform parent, InteractionSource source) { yield return(ControllerHelpers.AttachModel(target, parent, source, GLTFMaterial, GLTFMaterial)); if (AnimateControllerModel) { var newControllerInfo = new MotionControllerInfo() { }; newControllerInfo.LoadInfo(target.GetComponentsInChildren <Transform>(), this); controllerInfoForAnimation.Add(source.id, newControllerInfo); TraceHelper.Log("Controller added for animation"); } if (ShowDebugAxis) { if (source.handedness == InteractionSourceHandedness.Left) { axisRendererLeft = target.AddComponent <AxisRenderer>(); } else { axisRendererRight = target.AddComponent <AxisRenderer>(); } } }
protected virtual void AttachControllerModel(MotionControllerInfo controllerInfo) { if (controllerInfo.Handedness == Handedness) { Transform controllerTransform = controllerInfo.ControllerParent.transform; controllerTransform.SetParent(transform); controllerTransform.localPosition = Vector3.zero; controllerTransform.localRotation = Quaternion.identity; controllerTransform.localScale = Vector3.one; } }
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); } }