void OcclusionChanged() { if (GameplayReferences.GetControllerInfo(false, out tempInfo)) { if (tempInfo.connected != leftWasConnected) { //event new CustomEvent("cvr.tracking").SetProperty("device", "left").SetProperty("connected", tempInfo.connected).Send(); leftWasConnected = tempInfo.connected; } if (tempInfo.visible != leftWasVisible) { //event new CustomEvent("cvr.tracking").SetProperty("device", "left").SetProperty("visible", tempInfo.visible).Send(); leftWasVisible = tempInfo.visible; } } if (GameplayReferences.GetControllerInfo(true, out tempInfo)) { if (tempInfo.connected != rightWasConnected) { //event new CustomEvent("cvr.tracking").SetProperty("device", "right").SetProperty("connected", tempInfo.connected).Send(); rightWasConnected = tempInfo.connected; } if (tempInfo.visible != rightWasVisible) { //event new CustomEvent("cvr.tracking").SetProperty("device", "right").SetProperty("visible", tempInfo.visible).Send(); rightWasVisible = tempInfo.visible; } } }
private void CognitiveVR_Manager_UpdateEvent(float deltaTime) { if (GameplayReferences.HMD == null) { Core.UpdateEvent -= CognitiveVR_Manager_UpdateEvent; return; } //get left controller device if (leftController == null && GameplayReferences.GetControllerInfo(false, out tempInfo)) { var leftObject = tempInfo.transform.GetComponent <SteamVR_TrackedObject>(); if (leftObject != null) { leftController = SteamVR_Controller.Input((int)leftObject.index); } } //get right controller device if (rightController == null && GameplayReferences.GetControllerInfo(true, out tempInfo)) { var rightObject = tempInfo.transform.GetComponent <SteamVR_TrackedObject>(); if (rightObject != null) { rightController = SteamVR_Controller.Input((int)rightObject.index); } } if (!rightControllerTracking && rightController != null && rightController.GetHairTriggerDown()) { //start coroutine if not started already rightControllerTracking = true; if (!anyControllerTracking) { anyControllerTracking = true; StartCoroutine(Tick()); } } if (!leftControllerTracking && leftController != null && leftController.GetHairTriggerDown()) { //start coroutine if not started already leftControllerTracking = true; if (!anyControllerTracking) { anyControllerTracking = true; StartCoroutine(Tick()); } } //if both controllers are actively tracking distance, stop this callback to check for controllers that become active if (leftControllerTracking && rightControllerTracking) { Core.UpdateEvent -= CognitiveVR_Manager_UpdateEvent; } }
IEnumerator Tick() { int samples = 0; float maxSqrDistance = 0; while (samples < SampleCount) { yield return(new WaitForSeconds(Interval)); //if left controller is active, record max distance if (leftControllerTracking && GameplayReferences.GetControllerInfo(false, out tempInfo)) { if (tempInfo.connected && tempInfo.visible) { maxSqrDistance = Mathf.Max(maxSqrDistance, Vector3.SqrMagnitude(tempInfo.transform.position - (GameplayReferences.HMD.position - GameplayReferences.HMD.up * EyeToShoulderHeight))); } } //if right controller is active, record max distance if (rightControllerTracking && GameplayReferences.GetControllerInfo(true, out tempInfo)) { if (tempInfo.connected && tempInfo.visible) { maxSqrDistance = Mathf.Max(maxSqrDistance, Vector3.SqrMagnitude(tempInfo.transform.position - (GameplayReferences.HMD.position - GameplayReferences.HMD.up * EyeToShoulderHeight))); //Debug.DrawLine(GameplayReferences.HMD.position, GameplayReferences.HMD.position - GameplayReferences.HMD.up * EyeToShoulderHeight,Color.red,1); //Debug.DrawLine(tempInfo.transform.position, GameplayReferences.HMD.position - GameplayReferences.HMD.up * EyeToShoulderHeight,Color.blue,1); } } samples++; } if (maxSqrDistance > 0) { //send arm length float distance = Mathf.Sqrt(maxSqrDistance); //dashboard expects centimeters Core.SetParticipantProperty("armlength", distance * 100); } }
private void CognitiveVR_Manager_OnTick() { bool hit; if (GameplayReferences.GetControllerInfo(false, out tempInfo)) { if (tempInfo.connected && tempInfo.visible) { hit = Physics.CheckSphere(tempInfo.transform.position, 0.1f, CollisionLayerMask); if (hit && !LeftControllerColliding) { LeftControllerColliding = true; new CustomEvent("cvr.collision").SetProperty("device", "left controller").SetProperty("state", "begin").Send(); } else if (!hit && LeftControllerColliding) { new CustomEvent("cvr.collision").SetProperty("device", "left controller").SetProperty("state", "end").Send(); LeftControllerColliding = false; } } } if (GameplayReferences.GetControllerInfo(true, out tempInfo)) { if (tempInfo.connected && tempInfo.visible) { hit = Physics.CheckSphere(tempInfo.transform.position, 0.1f, CollisionLayerMask); if (hit && !RightControllerColliding) { RightControllerColliding = true; new CustomEvent("cvr.collision").SetProperty("device", "right controller").SetProperty("state", "begin").Send(); } else if (!hit && RightControllerColliding) { new CustomEvent("cvr.collision").SetProperty("device", "right controller").SetProperty("state", "end").Send(); RightControllerColliding = false; } } } }