protected virtual KnobDirection DetectDirection() { KnobDirection returnDirection = KnobDirection.x; Bounds bounds = VRTK_SharedMethods.GetBounds(transform); // shoot rays in all directions to learn about surroundings RaycastHit hitForward; RaycastHit hitBack; RaycastHit hitLeft; RaycastHit hitRight; RaycastHit hitUp; RaycastHit hitDown; Physics.Raycast(bounds.center, Vector3.forward, out hitForward, bounds.extents.z * MAX_AUTODETECT_KNOB_WIDTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.back, out hitBack, bounds.extents.z * MAX_AUTODETECT_KNOB_WIDTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.left, out hitLeft, bounds.extents.x * MAX_AUTODETECT_KNOB_WIDTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.right, out hitRight, bounds.extents.x * MAX_AUTODETECT_KNOB_WIDTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.up, out hitUp, bounds.extents.y * MAX_AUTODETECT_KNOB_WIDTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.down, out hitDown, bounds.extents.y * MAX_AUTODETECT_KNOB_WIDTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); // shortest valid ray wins float lengthX = (hitRight.collider != null) ? hitRight.distance : float.MaxValue; float lengthY = (hitDown.collider != null) ? hitDown.distance : float.MaxValue; float lengthZ = (hitBack.collider != null) ? hitBack.distance : float.MaxValue; float lengthNegX = (hitLeft.collider != null) ? hitLeft.distance : float.MaxValue; float lengthNegY = (hitUp.collider != null) ? hitUp.distance : float.MaxValue; float lengthNegZ = (hitForward.collider != null) ? hitForward.distance : float.MaxValue; // TODO: not yet the right decision strategy, works only partially if (VRTK_SharedMethods.IsLowest(lengthX, new float[] { lengthY, lengthZ, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = KnobDirection.z; } else if (VRTK_SharedMethods.IsLowest(lengthY, new float[] { lengthX, lengthZ, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = KnobDirection.y; } else if (VRTK_SharedMethods.IsLowest(lengthZ, new float[] { lengthX, lengthY, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = KnobDirection.x; } else if (VRTK_SharedMethods.IsLowest(lengthNegX, new float[] { lengthX, lengthY, lengthZ, lengthNegY, lengthNegZ })) { returnDirection = KnobDirection.z; } else if (VRTK_SharedMethods.IsLowest(lengthNegY, new float[] { lengthX, lengthY, lengthZ, lengthNegX, lengthNegZ })) { returnDirection = KnobDirection.y; } else if (VRTK_SharedMethods.IsLowest(lengthNegZ, new float[] { lengthX, lengthY, lengthZ, lengthNegX, lengthNegY })) { returnDirection = KnobDirection.x; } return(returnDirection); }
// Token: 0x060013E4 RID: 5092 RVA: 0x0006DAA0 File Offset: 0x0006BCA0 protected virtual VRTK_Control.Direction DetectDirection() { VRTK_Control.Direction result = VRTK_Control.Direction.autodetect; if (!this.handle) { return(result); } Bounds bounds = VRTK_SharedMethods.GetBounds(this.handle.transform, base.transform, null); Bounds bounds2 = VRTK_SharedMethods.GetBounds(this.lid.transform, base.transform, null); float num = Mathf.Abs(bounds.center.x - (bounds2.center.x + bounds2.extents.x)); float num2 = Mathf.Abs(bounds.center.z - (bounds2.center.z + bounds2.extents.z)); float num3 = Mathf.Abs(bounds.center.x - (bounds2.center.x - bounds2.extents.x)); float num4 = Mathf.Abs(bounds.center.z - (bounds2.center.z - bounds2.extents.z)); if (VRTK_SharedMethods.IsLowest(num, new float[] { num2, num3, num4 })) { result = VRTK_Control.Direction.x; } else if (VRTK_SharedMethods.IsLowest(num3, new float[] { num, num2, num4 })) { result = VRTK_Control.Direction.x; } else if (VRTK_SharedMethods.IsLowest(num2, new float[] { num, num3, num4 })) { result = VRTK_Control.Direction.z; } else if (VRTK_SharedMethods.IsLowest(num4, new float[] { num, num2, num3 })) { result = VRTK_Control.Direction.z; } return(result); }
protected virtual Direction DetectDirection() { Direction returnDirection = Direction.autodetect; Bounds handleBounds = VRTK_SharedMethods.GetBounds(GetHandle().transform, transform); Bounds bodyBounds = VRTK_SharedMethods.GetBounds(GetBody().transform, transform); float lengthX = Mathf.Abs(handleBounds.center.x - (bodyBounds.center.x + bodyBounds.extents.x)); float lengthY = Mathf.Abs(handleBounds.center.y - (bodyBounds.center.y + bodyBounds.extents.y)); float lengthZ = Mathf.Abs(handleBounds.center.z - (bodyBounds.center.z + bodyBounds.extents.z)); float lengthNegX = Mathf.Abs(handleBounds.center.x - (bodyBounds.center.x - bodyBounds.extents.x)); float lengthNegY = Mathf.Abs(handleBounds.center.y - (bodyBounds.center.y - bodyBounds.extents.y)); float lengthNegZ = Mathf.Abs(handleBounds.center.z - (bodyBounds.center.z - bodyBounds.extents.z)); if (VRTK_SharedMethods.IsLowest(lengthX, new float[] { lengthY, lengthZ, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = Direction.x; } else if (VRTK_SharedMethods.IsLowest(lengthNegX, new float[] { lengthX, lengthY, lengthZ, lengthNegY, lengthNegZ })) { returnDirection = Direction.x; } else if (VRTK_SharedMethods.IsLowest(lengthY, new float[] { lengthX, lengthZ, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = Direction.y; } else if (VRTK_SharedMethods.IsLowest(lengthNegY, new float[] { lengthX, lengthY, lengthZ, lengthNegX, lengthNegZ })) { returnDirection = Direction.y; } else if (VRTK_SharedMethods.IsLowest(lengthZ, new float[] { lengthX, lengthY, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = Direction.z; } else if (VRTK_SharedMethods.IsLowest(lengthNegZ, new float[] { lengthX, lengthY, lengthZ, lengthNegY, lengthNegX })) { returnDirection = Direction.z; } return(returnDirection); }
private Direction DetectDirection() { Direction returnDirection = Direction.autodetect; if (!handle) { return(returnDirection); } Bounds handleBounds = VRTK_SharedMethods.GetBounds(handle.transform, transform); Bounds lidBounds = VRTK_SharedMethods.GetBounds(lid.transform, transform); float lengthX = Mathf.Abs(handleBounds.center.x - (lidBounds.center.x + lidBounds.extents.x)); float lengthZ = Mathf.Abs(handleBounds.center.z - (lidBounds.center.z + lidBounds.extents.z)); float lengthNegX = Mathf.Abs(handleBounds.center.x - (lidBounds.center.x - lidBounds.extents.x)); float lengthNegZ = Mathf.Abs(handleBounds.center.z - (lidBounds.center.z - lidBounds.extents.z)); if (VRTK_SharedMethods.IsLowest(lengthX, new float[] { lengthZ, lengthNegX, lengthNegZ })) { returnDirection = Direction.x; } else if (VRTK_SharedMethods.IsLowest(lengthNegX, new float[] { lengthX, lengthZ, lengthNegZ })) { returnDirection = Direction.x; } else if (VRTK_SharedMethods.IsLowest(lengthZ, new float[] { lengthX, lengthNegX, lengthNegZ })) { returnDirection = Direction.z; } else if (VRTK_SharedMethods.IsLowest(lengthNegZ, new float[] { lengthX, lengthZ, lengthNegX })) { returnDirection = Direction.z; } return(returnDirection); }
protected virtual ButtonDirection DetectDirection() { ButtonDirection returnDirection = ButtonDirection.autodetect; Bounds bounds = VRTK_SharedMethods.GetBounds(transform); // shoot rays from the center of the button to learn about surroundings RaycastHit hitForward; RaycastHit hitBack; RaycastHit hitLeft; RaycastHit hitRight; RaycastHit hitUp; RaycastHit hitDown; Physics.Raycast(bounds.center, Vector3.forward, out hitForward, bounds.extents.z * MAX_AUTODETECT_ACTIVATION_LENGTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.back, out hitBack, bounds.extents.z * MAX_AUTODETECT_ACTIVATION_LENGTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.left, out hitLeft, bounds.extents.x * MAX_AUTODETECT_ACTIVATION_LENGTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.right, out hitRight, bounds.extents.x * MAX_AUTODETECT_ACTIVATION_LENGTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.up, out hitUp, bounds.extents.y * MAX_AUTODETECT_ACTIVATION_LENGTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, Vector3.down, out hitDown, bounds.extents.y * MAX_AUTODETECT_ACTIVATION_LENGTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); // shortest valid ray wins float lengthX = (hitRight.collider != null) ? hitRight.distance : float.MaxValue; float lengthY = (hitDown.collider != null) ? hitDown.distance : float.MaxValue; float lengthZ = (hitBack.collider != null) ? hitBack.distance : float.MaxValue; float lengthNegX = (hitLeft.collider != null) ? hitLeft.distance : float.MaxValue; float lengthNegY = (hitUp.collider != null) ? hitUp.distance : float.MaxValue; float lengthNegZ = (hitForward.collider != null) ? hitForward.distance : float.MaxValue; float extents = 0; Vector3 hitPoint = Vector3.zero; if (VRTK_SharedMethods.IsLowest(lengthX, new float[] { lengthY, lengthZ, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = ButtonDirection.negX; hitPoint = hitRight.point; extents = bounds.extents.x; } else if (VRTK_SharedMethods.IsLowest(lengthY, new float[] { lengthX, lengthZ, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = ButtonDirection.y; hitPoint = hitDown.point; extents = bounds.extents.y; } else if (VRTK_SharedMethods.IsLowest(lengthZ, new float[] { lengthX, lengthY, lengthNegX, lengthNegY, lengthNegZ })) { returnDirection = ButtonDirection.z; hitPoint = hitBack.point; extents = bounds.extents.z; } else if (VRTK_SharedMethods.IsLowest(lengthNegX, new float[] { lengthX, lengthY, lengthZ, lengthNegY, lengthNegZ })) { returnDirection = ButtonDirection.x; hitPoint = hitLeft.point; extents = bounds.extents.x; } else if (VRTK_SharedMethods.IsLowest(lengthNegY, new float[] { lengthX, lengthY, lengthZ, lengthNegX, lengthNegZ })) { returnDirection = ButtonDirection.negY; hitPoint = hitUp.point; extents = bounds.extents.y; } else if (VRTK_SharedMethods.IsLowest(lengthNegZ, new float[] { lengthX, lengthY, lengthZ, lengthNegX, lengthNegY })) { returnDirection = ButtonDirection.negZ; hitPoint = hitForward.point; extents = bounds.extents.z; } // determin activation distance activationDistance = (Vector3.Distance(hitPoint, bounds.center) - extents) * 0.95f; if (returnDirection == ButtonDirection.autodetect || activationDistance < 0.001f) { // auto-detection was not possible or colliding with object already returnDirection = ButtonDirection.autodetect; activationDistance = 0; } else { activationDir = hitPoint - bounds.center; } return(returnDirection); }
// Token: 0x06001425 RID: 5157 RVA: 0x0006FF10 File Offset: 0x0006E110 protected virtual VRTK_Knob.KnobDirection DetectDirection() { VRTK_Knob.KnobDirection result = VRTK_Knob.KnobDirection.x; Bounds bounds = VRTK_SharedMethods.GetBounds(base.transform, null, null); RaycastHit raycastHit; Physics.Raycast(bounds.center, Vector3.forward, out raycastHit, bounds.extents.z * 3f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit2; Physics.Raycast(bounds.center, Vector3.back, out raycastHit2, bounds.extents.z * 3f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit3; Physics.Raycast(bounds.center, Vector3.left, out raycastHit3, bounds.extents.x * 3f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit4; Physics.Raycast(bounds.center, Vector3.right, out raycastHit4, bounds.extents.x * 3f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit5; Physics.Raycast(bounds.center, Vector3.up, out raycastHit5, bounds.extents.y * 3f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit6; Physics.Raycast(bounds.center, Vector3.down, out raycastHit6, bounds.extents.y * 3f, -5, QueryTriggerInteraction.UseGlobal); float num = (raycastHit4.collider != null) ? raycastHit4.distance : float.MaxValue; float num2 = (raycastHit6.collider != null) ? raycastHit6.distance : float.MaxValue; float num3 = (raycastHit2.collider != null) ? raycastHit2.distance : float.MaxValue; float num4 = (raycastHit3.collider != null) ? raycastHit3.distance : float.MaxValue; float num5 = (raycastHit5.collider != null) ? raycastHit5.distance : float.MaxValue; float num6 = (raycastHit.collider != null) ? raycastHit.distance : float.MaxValue; if (VRTK_SharedMethods.IsLowest(num, new float[] { num2, num3, num4, num5, num6 })) { result = VRTK_Knob.KnobDirection.z; } else if (VRTK_SharedMethods.IsLowest(num2, new float[] { num, num3, num4, num5, num6 })) { result = VRTK_Knob.KnobDirection.y; } else if (VRTK_SharedMethods.IsLowest(num3, new float[] { num, num2, num4, num5, num6 })) { result = VRTK_Knob.KnobDirection.x; } else if (VRTK_SharedMethods.IsLowest(num4, new float[] { num, num2, num3, num5, num6 })) { result = VRTK_Knob.KnobDirection.z; } else if (VRTK_SharedMethods.IsLowest(num5, new float[] { num, num2, num3, num4, num6 })) { result = VRTK_Knob.KnobDirection.y; } else if (VRTK_SharedMethods.IsLowest(num6, new float[] { num, num2, num3, num4, num5 })) { result = VRTK_Knob.KnobDirection.x; } return(result); }
// Token: 0x060013DA RID: 5082 RVA: 0x0006CE60 File Offset: 0x0006B060 protected virtual VRTK_Button.ButtonDirection DetectDirection() { VRTK_Button.ButtonDirection buttonDirection = VRTK_Button.ButtonDirection.autodetect; Bounds bounds = VRTK_SharedMethods.GetBounds(base.transform, null, null); RaycastHit raycastHit; Physics.Raycast(bounds.center, Vector3.forward, out raycastHit, bounds.extents.z * 4f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit2; Physics.Raycast(bounds.center, Vector3.back, out raycastHit2, bounds.extents.z * 4f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit3; Physics.Raycast(bounds.center, Vector3.left, out raycastHit3, bounds.extents.x * 4f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit4; Physics.Raycast(bounds.center, Vector3.right, out raycastHit4, bounds.extents.x * 4f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit5; Physics.Raycast(bounds.center, Vector3.up, out raycastHit5, bounds.extents.y * 4f, -5, QueryTriggerInteraction.UseGlobal); RaycastHit raycastHit6; Physics.Raycast(bounds.center, Vector3.down, out raycastHit6, bounds.extents.y * 4f, -5, QueryTriggerInteraction.UseGlobal); float num = (raycastHit4.collider != null) ? raycastHit4.distance : float.MaxValue; float num2 = (raycastHit6.collider != null) ? raycastHit6.distance : float.MaxValue; float num3 = (raycastHit2.collider != null) ? raycastHit2.distance : float.MaxValue; float num4 = (raycastHit3.collider != null) ? raycastHit3.distance : float.MaxValue; float num5 = (raycastHit5.collider != null) ? raycastHit5.distance : float.MaxValue; float num6 = (raycastHit.collider != null) ? raycastHit.distance : float.MaxValue; float num7 = 0f; Vector3 a = Vector3.zero; if (VRTK_SharedMethods.IsLowest(num, new float[] { num2, num3, num4, num5, num6 })) { buttonDirection = VRTK_Button.ButtonDirection.negX; a = raycastHit4.point; num7 = bounds.extents.x; } else if (VRTK_SharedMethods.IsLowest(num2, new float[] { num, num3, num4, num5, num6 })) { buttonDirection = VRTK_Button.ButtonDirection.y; a = raycastHit6.point; num7 = bounds.extents.y; } else if (VRTK_SharedMethods.IsLowest(num3, new float[] { num, num2, num4, num5, num6 })) { buttonDirection = VRTK_Button.ButtonDirection.z; a = raycastHit2.point; num7 = bounds.extents.z; } else if (VRTK_SharedMethods.IsLowest(num4, new float[] { num, num2, num3, num5, num6 })) { buttonDirection = VRTK_Button.ButtonDirection.x; a = raycastHit3.point; num7 = bounds.extents.x; } else if (VRTK_SharedMethods.IsLowest(num5, new float[] { num, num2, num3, num4, num6 })) { buttonDirection = VRTK_Button.ButtonDirection.negY; a = raycastHit5.point; num7 = bounds.extents.y; } else if (VRTK_SharedMethods.IsLowest(num6, new float[] { num, num2, num3, num4, num5 })) { buttonDirection = VRTK_Button.ButtonDirection.negZ; a = raycastHit.point; num7 = bounds.extents.z; } this.activationDistance = (Vector3.Distance(a, bounds.center) - num7) * 0.95f; if (buttonDirection == VRTK_Button.ButtonDirection.autodetect || this.activationDistance < 0.001f) { buttonDirection = VRTK_Button.ButtonDirection.autodetect; this.activationDistance = 0f; } else { this.activationDir = a - bounds.center; } return(buttonDirection); }