private void RemoveController(IVRAvatarHand hand, bool keepChildren) { if (hand == null || hand.Transform == null) { return; } var controller = hand.Transform.GetComponentInChildren <VRAvatarController>(); if (controller == null) { return; } if (keepChildren) { for (int i = 0; i < controller.transform.childCount; ++i) { var child = controller.transform.GetChild(i); child.transform.parent = controller.transform.parent; } } DestroyImmediate(controller.gameObject, false); }
private IEnumerator MigrateModel(SteamVR_RenderModel model, IVRAvatarHand hand) { var controllerVisual = hand.Transform.GetComponentInChildren <VRAvatarController>(includeInactive: true); yield return(new WaitUntil(() => model.transform.childCount != 1)); if (controllerVisual == null) { model.SetMeshRendererState(false); yield break; } model.transform.SetParent(controllerVisual.transform); model.transform.localPosition = Vector3.zero; model.transform.localRotation = Quaternion.identity; switch (XRDeviceUtils.GetDeviceModelType()) { case EDeviceModelType.HtcVive: case EDeviceModelType.HtcViveCosmos: case EDeviceModelType.HtcVivePro: hand.Anchor.transform.localPosition += new Vector3(0, 0, -0.1f); model.transform.localPosition = new Vector3(0, 0, 0.1f); break; } var pointerVisual = controllerVisual.GetComponentInChildren <LaserPointerVisual>(includeInactive: true); pointerVisual.Bind(hand.InputDevice.Pointer); hand.InputDevice.Pointer.Transform = pointerVisual.transform; }
private bool ControllerHasChildren(IVRAvatarHand hand) { if (hand == null || hand.Transform == null) { return(false); } var controller = hand.Transform.GetComponentInChildren <VRAvatarController>(); if (controller == null) { return(false); } return(controller.transform.childCount > 0); }
private void AddController(IVRAvatarHand hand) { if (hand == null || hand.Transform == null) { return; } var controller = hand.Transform.GetComponentInChildren <VRAvatarController>(); if (controller == null) { controller = new GameObject("Controller").AddComponent <VRAvatarController>(); controller.transform.parent = hand.Anchor; controller.transform.Identity(); } // Ensure the controller is nested under the anchor controller.transform.parent = hand.Anchor; controller.transform.Identity(); }