// Token: 0x0600140A RID: 5130 RVA: 0x0006EE28 File Offset: 0x0006D028 protected virtual VRTK_Control.Direction DetectDirection() { VRTK_Control.Direction result = VRTK_Control.Direction.autodetect; if (this.doorHinge && !this.doorHingeCreated) { if (this.doorHinge.axis == Vector3.right) { result = VRTK_Control.Direction.x; } else if (this.doorHinge.axis == Vector3.up) { result = VRTK_Control.Direction.y; } else if (this.doorHinge.axis == Vector3.forward) { result = VRTK_Control.Direction.z; } } else if (this.handles) { Bounds bounds = VRTK_SharedMethods.GetBounds(this.handles.transform, base.transform, null); Bounds bounds2 = VRTK_SharedMethods.GetBounds(this.GetDoor().transform, base.transform, this.handles.transform); if (bounds.center.y + bounds.extents.y > bounds2.center.y + bounds2.extents.y || bounds.center.y - bounds.extents.y < bounds2.center.y - bounds2.extents.y) { result = VRTK_Control.Direction.x; } else { result = VRTK_Control.Direction.y; } } return(result); }
// Token: 0x06001414 RID: 5140 RVA: 0x0006F2AC File Offset: 0x0006D4AC protected override void OnDrawGizmos() { base.OnDrawGizmos(); if (!base.enabled || !this.setupSuccessful) { return; } Bounds bounds = VRTK_SharedMethods.GetBounds(this.GetHandle().transform, this.GetHandle().transform, null); float num = bounds.extents.y * (this.handle ? 5f : 1f); Vector3 vector = bounds.center; switch (this.finalDirection) { case VRTK_Control.Direction.x: vector -= base.transform.right.normalized * (num * this.subDirection); break; case VRTK_Control.Direction.y: vector -= base.transform.up.normalized * (num * this.subDirection); break; case VRTK_Control.Direction.z: vector -= base.transform.forward.normalized * (num * this.subDirection); break; } Gizmos.DrawLine(bounds.center, vector); Gizmos.DrawSphere(vector, num / 4f); }
protected override void OnDrawGizmos() { base.OnDrawGizmos(); if (!enabled || !setupSuccessful) { return; } // show opening direction Bounds handleBounds = VRTK_SharedMethods.GetBounds(GetHandle().transform, GetHandle().transform); float length = handleBounds.extents.y * ((handle) ? 5f : 1f); Vector3 point = handleBounds.center; switch (finalDirection) { case Direction.x: point -= transform.right.normalized * (length * subDirection); break; case Direction.y: point -= transform.up.normalized * (length * subDirection); break; case Direction.z: point -= transform.forward.normalized * (length * subDirection); break; } Gizmos.DrawLine(handleBounds.center, point); Gizmos.DrawSphere(point, length / 4f); }
private float CalculateValue() { Vector3 center = (direction == Direction.autodetect) ? VRTK_SharedMethods.GetBounds(transform).center : transform.position; float dist1 = Vector3.Distance(finalMinPoint, center); float dist2 = Vector3.Distance(center, finalMaxPoint); return(Mathf.Round((min + Mathf.Clamp01(dist1 / (dist1 + dist2)) * (max - min)) / stepSize) * stepSize); }
protected virtual void OnDrawGizmosSelected() { if (highlightObject != null && !displayDropZoneInEditor) { Vector3 boxSize = VRTK_SharedMethods.GetBounds(highlightObject.transform).size * 1.05f; Gizmos.color = Color.red; Gizmos.DrawWireCube(highlightObject.transform.position, boxSize); } }
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: 0x060013C6 RID: 5062 RVA: 0x0006C740 File Offset: 0x0006A940 protected virtual void OnCollisionEnter(Collision collision) { Bounds bounds = VRTK_SharedMethods.GetBounds(this.inside, null, this.control.GetContent().transform); if (VRTK_SharedMethods.GetBounds(base.transform, null, null).Intersects(bounds)) { base.transform.SetParent(this.control.GetContent().transform); return; } base.transform.SetParent(this.outside); }
// 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 void OnCollisionEnter(Collision collision) { Bounds insideBounds = VRTK_SharedMethods.GetBounds(inside, null, control.GetContent().transform); Bounds objBounds = VRTK_SharedMethods.GetBounds(transform); if (objBounds.Intersects(insideBounds)) { transform.SetParent(control.GetContent().transform); } else { transform.SetParent(outside); } }
private void OnCollisionEnter(Collision collision) { Bounds insideBounds = VRTK_SharedMethods.GetBounds(inside, null, control.GetContent().transform); Bounds objBounds = VRTK_SharedMethods.GetBounds(transform); if (objBounds.Intersects(insideBounds)) { transform.parent = control.GetContent().transform; } else { transform.parent = outside; } }
private bool DoDetectMinMax(Direction direction) { Bounds bounds = VRTK_SharedMethods.GetBounds(transform); Vector3 v = Vector3.zero; float extents = 0; switch (direction) { case Direction.x: v = Vector3.left; extents = bounds.extents.x; break; case Direction.y: v = Vector3.down; extents = bounds.extents.y; break; case Direction.z: v = Vector3.forward; extents = bounds.extents.z; break; } RaycastHit hit1; RaycastHit hit2; Physics.Raycast(bounds.center, v, out hit1, extents * MAX_AUTODETECT_SLIDER_LENGTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); Physics.Raycast(bounds.center, v * -1, out hit2, extents * MAX_AUTODETECT_SLIDER_LENGTH, Physics.DefaultRaycastLayers, QueryTriggerInteraction.UseGlobal); if (hit1.collider && hit2.collider) { finalMinPoint = hit1.point; finalMaxPoint = hit2.point; // subtract width of slider to reach all values finalMinPoint = finalMinPoint + (finalMaxPoint - finalMinPoint).normalized * extents; finalMaxPoint = finalMaxPoint - (finalMaxPoint - finalMinPoint).normalized * extents; return(true); } else { finalMinPoint = transform.position; finalMaxPoint = transform.position; } return(false); }
// Token: 0x060013FD RID: 5117 RVA: 0x0006E080 File Offset: 0x0006C280 protected virtual void OnDrawGizmos() { if (!base.enabled) { return; } this.bounds = VRTK_SharedMethods.GetBounds(base.transform, null, null); Gizmos.color = (this.setupSuccessful ? VRTK_Control.COLOR_OK : VRTK_Control.COLOR_ERROR); if (this.setupSuccessful) { Gizmos.DrawWireCube(this.bounds.center, this.bounds.size); return; } Gizmos.DrawCube(this.bounds.center, this.bounds.size * 1.01f); }
// Token: 0x060013FE RID: 5118 RVA: 0x0006E10C File Offset: 0x0006C30C protected virtual void CreateTriggerVolume() { GameObject gameObject = new GameObject(base.name + "-Trigger"); gameObject.transform.SetParent(base.transform); this.autoTriggerVolume = gameObject.AddComponent <VRTK_ControllerRigidbodyActivator>(); Bounds bounds = VRTK_SharedMethods.GetBounds(base.transform, null, null); bounds.Expand(bounds.size * 0.2f); gameObject.transform.position = bounds.center; BoxCollider boxCollider = gameObject.AddComponent <BoxCollider>(); boxCollider.isTrigger = true; boxCollider.size = bounds.size; }
protected virtual void CreateTriggerVolume() { GameObject autoTriggerVolumeGO = new GameObject(name + "-Trigger"); autoTriggerVolumeGO.transform.SetParent(transform); autoTriggerVolume = autoTriggerVolumeGO.AddComponent <VRTK_ControllerRigidbodyActivator>(); // calculate bounding box Bounds triggerBounds = VRTK_SharedMethods.GetBounds(transform); triggerBounds.Expand(triggerBounds.size * 0.2f); autoTriggerVolumeGO.transform.position = triggerBounds.center; BoxCollider triggerCollider = autoTriggerVolumeGO.AddComponent <BoxCollider>(); triggerCollider.isTrigger = true; triggerCollider.size = triggerBounds.size; }
private void CreateTriggerVolume() { GameObject tvGo = new GameObject(name + "-Trigger"); tvGo.transform.SetParent(transform); tvGo.AddComponent <VRTK_ControllerRigidbodyActivator>(); // calculate bounding box Bounds bounds = VRTK_SharedMethods.GetBounds(transform); bounds.Expand(bounds.size * 0.2f); tvGo.transform.position = bounds.center; BoxCollider bc = tvGo.AddComponent <BoxCollider>(); bc.isTrigger = true; bc.size = bounds.size; }
protected virtual void OnDrawGizmos() { if (!enabled) { return; } bounds = VRTK_SharedMethods.GetBounds(transform); Gizmos.color = (setupSuccessful) ? COLOR_OK : COLOR_ERROR; if (setupSuccessful) { Gizmos.DrawWireCube(bounds.center, bounds.size); } else { Gizmos.DrawCube(bounds.center, bounds.size * 1.01f); // draw slightly bigger to eliminate flickering } }
private Direction DetectDirection() { Direction returnDirection = Direction.autodetect; if (doorHinge && !doorHingeCreated) { // use direction of hinge joint if (doorHinge.axis == Vector3.right) { returnDirection = Direction.x; } else if (doorHinge.axis == Vector3.up) { returnDirection = Direction.y; } else if (doorHinge.axis == Vector3.forward) { returnDirection = Direction.z; } } else { if (handles) { Bounds handleBounds = VRTK_SharedMethods.GetBounds(handles.transform, transform); Bounds doorBounds = VRTK_SharedMethods.GetBounds(GetDoor().transform, transform, handles.transform); // handles determine direction, there are actually two directions possible depending on handle position, we'll just detect one of them for now, preference is y if ((handleBounds.center.y + handleBounds.extents.y) > (doorBounds.center.y + doorBounds.extents.y) || (handleBounds.center.y - handleBounds.extents.y) < (doorBounds.center.y - doorBounds.extents.y)) { returnDirection = Direction.x; } else { returnDirection = Direction.y; } } } return(returnDirection); }
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 float subDirection = 1; // positive or negative can be determined automatically since handle dictates that protected override void OnDrawGizmos() { base.OnDrawGizmos(); if (!enabled || !setupSuccessful) { return; } // show opening direction Bounds bounds; if (handle) { bounds = VRTK_SharedMethods.GetBounds(handle.transform, handle.transform); } else { bounds = VRTK_SharedMethods.GetBounds(lid.transform, lid.transform); } float length = bounds.extents.y * 5f; Vector3 point = bounds.center + new Vector3(0, length, 0); switch (finalDirection) { case Direction.x: point += transform.right.normalized * (length / 2f) * subDirection; break; case Direction.y: point += transform.up.normalized * (length / 2f) * subDirection; break; case Direction.z: point += transform.forward.normalized * (length / 2f) * subDirection; break; } Gizmos.DrawLine(bounds.center + new Vector3(0, bounds.extents.y, 0), point); Gizmos.DrawSphere(point, length / 8f); }
protected override bool DetectSetup() { if (leverHingeJointCreated) { Bounds bounds = VRTK_SharedMethods.GetBounds(transform, transform); switch (direction) { case LeverDirection.x: leverHingeJoint.anchor = (bounds.extents.y > bounds.extents.z) ? new Vector3(0, bounds.extents.y / transform.lossyScale.y, 0) : new Vector3(0, 0, bounds.extents.z / transform.lossyScale.z); break; case LeverDirection.y: leverHingeJoint.axis = new Vector3(0, 1, 0); leverHingeJoint.anchor = (bounds.extents.x > bounds.extents.z) ? new Vector3(bounds.extents.x / transform.lossyScale.x, 0, 0) : new Vector3(0, 0, bounds.extents.z / transform.lossyScale.z); break; case LeverDirection.z: leverHingeJoint.axis = new Vector3(0, 0, 1); leverHingeJoint.anchor = (bounds.extents.y > bounds.extents.x) ? new Vector3(0, bounds.extents.y / transform.lossyScale.y, 0) : new Vector3(bounds.extents.x / transform.lossyScale.x, 0); break; } leverHingeJoint.anchor *= -1; // subdirection detection not yet implemented } if (leverHingeJoint) { leverHingeJoint.useLimits = true; JointLimits leverJointLimits = leverHingeJoint.limits; leverJointLimits.min = minAngle; leverJointLimits.max = maxAngle; leverHingeJoint.limits = leverJointLimits; if (connectedTo) { leverHingeJoint.connectedBody = connectedTo.GetComponent <Rigidbody>(); } } return(true); }
// Token: 0x060013DF RID: 5087 RVA: 0x0006D528 File Offset: 0x0006B728 protected override void OnDrawGizmos() { base.OnDrawGizmos(); if (!base.enabled || !this.setupSuccessful) { return; } Bounds bounds; if (this.handle) { bounds = VRTK_SharedMethods.GetBounds(this.handle.transform, this.handle.transform, null); } else { bounds = VRTK_SharedMethods.GetBounds(this.lid.transform, this.lid.transform, null); } float num = bounds.extents.y * 5f; Vector3 vector = bounds.center + new Vector3(0f, num, 0f); switch (this.finalDirection) { case VRTK_Control.Direction.x: vector += base.transform.right.normalized * (num / 2f) * this.subDirection; break; case VRTK_Control.Direction.y: vector += base.transform.up.normalized * (num / 2f) * this.subDirection; break; case VRTK_Control.Direction.z: vector += base.transform.forward.normalized * (num / 2f) * this.subDirection; break; } Gizmos.DrawLine(bounds.center + new Vector3(0f, bounds.extents.y, 0f), vector); Gizmos.DrawSphere(vector, num / 8f); }
// Token: 0x06001429 RID: 5161 RVA: 0x000704B8 File Offset: 0x0006E6B8 protected override bool DetectSetup() { if (this.leverHingeJointCreated) { Bounds bounds = VRTK_SharedMethods.GetBounds(base.transform, base.transform, null); switch (this.direction) { case VRTK_Lever.LeverDirection.x: this.leverHingeJoint.anchor = ((bounds.extents.y > bounds.extents.z) ? new Vector3(0f, bounds.extents.y / base.transform.lossyScale.y, 0f) : new Vector3(0f, 0f, bounds.extents.z / base.transform.lossyScale.z)); break; case VRTK_Lever.LeverDirection.y: this.leverHingeJoint.axis = new Vector3(0f, 1f, 0f); this.leverHingeJoint.anchor = ((bounds.extents.x > bounds.extents.z) ? new Vector3(bounds.extents.x / base.transform.lossyScale.x, 0f, 0f) : new Vector3(0f, 0f, bounds.extents.z / base.transform.lossyScale.z)); break; case VRTK_Lever.LeverDirection.z: this.leverHingeJoint.axis = new Vector3(0f, 0f, 1f); this.leverHingeJoint.anchor = ((bounds.extents.y > bounds.extents.x) ? new Vector3(0f, bounds.extents.y / base.transform.lossyScale.y, 0f) : new Vector3(bounds.extents.x / base.transform.lossyScale.x, 0f)); break; } this.leverHingeJoint.anchor *= -1f; } if (this.leverHingeJoint) { this.leverHingeJoint.useLimits = true; JointLimits limits = this.leverHingeJoint.limits; limits.min = this.minAngle; limits.max = this.maxAngle; this.leverHingeJoint.limits = limits; if (this.connectedTo) { this.leverHingeJoint.connectedBody = this.connectedTo.GetComponent <Rigidbody>(); } } return(true); }
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 override bool DetectSetup() { // detect axis doorHinge = GetDoor().GetComponent <HingeJoint>(); if (doorHinge && !doorHingeCreated) { direction = Direction.autodetect; } finalDirection = (direction == Direction.autodetect) ? DetectDirection() : direction; if (finalDirection == Direction.autodetect) { return(false); } if (doorHinge && !doorHingeCreated) { // if there is a hinge joint already it overrides axis selection direction = finalDirection; } // detect opening direction Bounds doorBounds = VRTK_SharedMethods.GetBounds(GetDoor().transform, transform); if (doorHinge == null || doorHingeCreated) { if (handles) { // determin sub-direction depending on handle location Bounds handleBounds = VRTK_SharedMethods.GetBounds(handles.transform, transform); switch (finalDirection) { case Direction.x: if ((handleBounds.center.z + handleBounds.extents.z) > (doorBounds.center.z + doorBounds.extents.z) || (handleBounds.center.z - handleBounds.extents.z) < (doorBounds.center.z - doorBounds.extents.z)) { subDirection = (handleBounds.center.y > doorBounds.center.y) ? -1 : 1; secondaryDirection = Vector3.up; } else { subDirection = (handleBounds.center.z > doorBounds.center.z) ? -1 : 1; secondaryDirection = Vector3.forward; } break; case Direction.y: if ((handleBounds.center.z + handleBounds.extents.z) > (doorBounds.center.z + doorBounds.extents.z) || (handleBounds.center.z - handleBounds.extents.z) < (doorBounds.center.z - doorBounds.extents.z)) { subDirection = (handleBounds.center.x > doorBounds.center.x) ? -1 : 1; secondaryDirection = Vector3.right; } else { subDirection = (handleBounds.center.z > doorBounds.center.z) ? -1 : 1; secondaryDirection = Vector3.forward; } break; case Direction.z: if ((handleBounds.center.x + handleBounds.extents.x) > (doorBounds.center.x + doorBounds.extents.x) || (handleBounds.center.x - handleBounds.extents.x) < (doorBounds.center.x - doorBounds.extents.x)) { subDirection = (handleBounds.center.y > doorBounds.center.y) ? -1 : 1; secondaryDirection = Vector3.up; } else { subDirection = (handleBounds.center.x > doorBounds.center.x) ? -1 : 1; secondaryDirection = Vector3.right; } break; } } else { switch (finalDirection) { case Direction.x: secondaryDirection = (doorBounds.extents.y > doorBounds.extents.z) ? Vector3.up : Vector3.forward; break; case Direction.y: secondaryDirection = (doorBounds.extents.x > doorBounds.extents.z) ? Vector3.right : Vector3.forward; break; case Direction.z: secondaryDirection = (doorBounds.extents.y > doorBounds.extents.x) ? Vector3.up : Vector3.right; break; } // TODO: derive how to detect -1 subDirection = 1; } } else { // calculate directions from existing anchor Vector3 existingAnchorDirection = doorBounds.center - doorHinge.connectedAnchor; if (existingAnchorDirection.x != 0) { secondaryDirection = Vector3.right; subDirection = existingAnchorDirection.x <= 0 ? 1 : -1; } else if (existingAnchorDirection.y != 0) { secondaryDirection = Vector3.up; subDirection = existingAnchorDirection.y <= 0 ? 1 : -1; } else if (existingAnchorDirection.z != 0) { secondaryDirection = Vector3.forward; subDirection = existingAnchorDirection.z <= 0 ? 1 : -1; } } if (doorHingeCreated) { float extents = 0; if (secondaryDirection == Vector3.right) { extents = doorBounds.extents.x / GetDoor().transform.lossyScale.x; } else if (secondaryDirection == Vector3.up) { extents = doorBounds.extents.y / GetDoor().transform.lossyScale.y; } else { extents = doorBounds.extents.z / GetDoor().transform.lossyScale.z; } doorHinge.anchor = secondaryDirection * subDirection * extents; doorHinge.axis = Direction2Axis(finalDirection); } if (doorHinge) { doorHinge.useLimits = true; doorHinge.enableCollision = true; JointLimits limits = doorHinge.limits; limits.min = openInward ? -maxAngle : 0; limits.max = openOutward ? maxAngle : 0; limits.bounciness = 0; doorHinge.limits = limits; } if (doorSnapForceCreated) { float forceToApply = (-5f * GetDirectionFromJoint()); doorSnapForce.relativeForce = GetThirdDirection(doorHinge.axis, secondaryDirection) * (subDirection * forceToApply); } return(true); }
// 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); }
protected override bool DetectSetup() { finalDirection = (direction == Direction.autodetect ? DetectDirection() : direction); if (finalDirection == Direction.autodetect) { return(false); } // determin sub-direction depending on handle Bounds handleBounds = VRTK_SharedMethods.GetBounds(GetHandle().transform, transform); Bounds bodyBounds = VRTK_SharedMethods.GetBounds(GetBody().transform, transform); switch (finalDirection) { case Direction.x: subDirection = (handleBounds.center.x > bodyBounds.center.x) ? -1 : 1; pullDistance = bodyBounds.extents.x; break; case Direction.y: subDirection = (handleBounds.center.y > bodyBounds.center.y) ? -1 : 1; pullDistance = bodyBounds.extents.y; break; case Direction.z: subDirection = (handleBounds.center.z > bodyBounds.center.z) ? -1 : 1; pullDistance = bodyBounds.extents.z; break; } if (body & handle) { // handle should be outside body hierarchy, otherwise anchor-by-bounds calculation is off if (handle.transform.IsChildOf(body.transform)) { return(false); } } if (drawerJointCreated) { drawerJoint.xMotion = ConfigurableJointMotion.Locked; drawerJoint.yMotion = ConfigurableJointMotion.Locked; drawerJoint.zMotion = ConfigurableJointMotion.Locked; switch (finalDirection) { case Direction.x: drawerJoint.axis = Vector3.right; drawerJoint.xMotion = ConfigurableJointMotion.Limited; break; case Direction.y: drawerJoint.axis = Vector3.up; drawerJoint.yMotion = ConfigurableJointMotion.Limited; break; case Direction.z: drawerJoint.axis = Vector3.forward; drawerJoint.zMotion = ConfigurableJointMotion.Limited; break; } drawerJoint.anchor = drawerJoint.axis * (-subDirection * pullDistance); } if (drawerJoint) { drawerJoint.angularXMotion = ConfigurableJointMotion.Locked; drawerJoint.angularYMotion = ConfigurableJointMotion.Locked; drawerJoint.angularZMotion = ConfigurableJointMotion.Locked; pullDistance *= (maxExtend * 1.8f); // don't let it pull out completely SoftJointLimit drawerJointLimit = drawerJoint.linearLimit; drawerJointLimit.limit = pullDistance; drawerJoint.linearLimit = drawerJointLimit; if (connectedTo) { drawerJoint.connectedBody = connectedTo.GetComponent <Rigidbody>(); } } if (drawerSnapForceCreated) { drawerSnapForce.force = transform.TransformDirection(drawerJoint.axis) * (subDirection * 50f); } return(true); }
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); }
protected virtual Vector3 CalculateActivationDir() { Bounds bounds = VRTK_SharedMethods.GetBounds(transform, transform); Vector3 buttonDirection = Vector3.zero; float extents = 0; switch (direction) { case ButtonDirection.x: case ButtonDirection.negX: if (Mathf.RoundToInt(Mathf.Abs(transform.right.x)) == 1) { buttonDirection = transform.right; extents = bounds.extents.x; } else if (Mathf.RoundToInt(Mathf.Abs(transform.up.x)) == 1) { buttonDirection = transform.up; extents = bounds.extents.y; } else if (Mathf.RoundToInt(Mathf.Abs(transform.forward.x)) == 1) { buttonDirection = transform.forward; extents = bounds.extents.z; } buttonDirection *= (direction == ButtonDirection.x) ? -1 : 1; break; case ButtonDirection.y: case ButtonDirection.negY: if (Mathf.RoundToInt(Mathf.Abs(transform.right.y)) == 1) { buttonDirection = transform.right; extents = bounds.extents.x; } else if (Mathf.RoundToInt(Mathf.Abs(transform.up.y)) == 1) { buttonDirection = transform.up; extents = bounds.extents.y; } else if (Mathf.RoundToInt(Mathf.Abs(transform.forward.y)) == 1) { buttonDirection = transform.forward; extents = bounds.extents.z; } buttonDirection *= (direction == ButtonDirection.y) ? -1 : 1; break; case ButtonDirection.z: case ButtonDirection.negZ: if (Mathf.RoundToInt(Mathf.Abs(transform.right.z)) == 1) { buttonDirection = transform.right; extents = bounds.extents.x; } else if (Mathf.RoundToInt(Mathf.Abs(transform.up.z)) == 1) { buttonDirection = transform.up; extents = bounds.extents.y; } else if (Mathf.RoundToInt(Mathf.Abs(transform.forward.z)) == 1) { buttonDirection = transform.forward; extents = bounds.extents.z; } buttonDirection *= (direction == ButtonDirection.z) ? -1 : 1; break; } // subtract width of button return(buttonDirection * (extents + activationDistance)); }
protected override void OnDrawGizmos() { base.OnDrawGizmos(); if (!enabled || !setupSuccessful) { return; } // show opening direction Bounds handleBounds = new Bounds(); Bounds doorBounds = VRTK_SharedMethods.GetBounds(GetDoor().transform, GetDoor().transform); float extensionLength = 0.5f; if (handles) { handleBounds = VRTK_SharedMethods.GetBounds(handles.transform, handles.transform); } Vector3 firstDirection = Vector3.zero; Vector3 secondDirection = Vector3.zero; Vector3 thirdDirection = GetThirdDirection(Direction2Axis(finalDirection), secondaryDirection); bool invertGizmos = false; switch (finalDirection) { case Direction.x: if (thirdDirection == Vector3.up) { firstDirection = transform.up.normalized; secondDirection = transform.forward.normalized; extensionLength *= doorBounds.extents.z; } else { firstDirection = transform.forward.normalized; secondDirection = transform.up.normalized; extensionLength *= doorBounds.extents.y; invertGizmos = true; } break; case Direction.y: if (thirdDirection == Vector3.right) { firstDirection = transform.right.normalized; secondDirection = transform.forward.normalized; extensionLength *= doorBounds.extents.z; invertGizmos = true; } else { firstDirection = transform.forward.normalized; secondDirection = transform.right.normalized; extensionLength *= doorBounds.extents.x; } break; case Direction.z: if (thirdDirection == Vector3.up) { firstDirection = transform.up.normalized; secondDirection = transform.right.normalized; extensionLength *= doorBounds.extents.x; invertGizmos = true; } else { firstDirection = transform.right.normalized; secondDirection = transform.up.normalized; extensionLength *= doorBounds.extents.y; } break; } if ((!invertGizmos && openInward) || (invertGizmos && openOutward)) { Vector3 point1Start = (handles) ? handleBounds.center : doorBounds.center; Vector3 point1End = point1Start + secondDirection * extensionLength * subDirection - firstDirection * (extensionLength / 2f) * subDirection; Gizmos.DrawLine(point1Start, point1End); Gizmos.DrawSphere(point1End, extensionLength / 8f); } if ((!invertGizmos && openOutward) || (invertGizmos && openInward)) { Vector3 point2Start = (handles) ? handleBounds.center : doorBounds.center; Vector3 point2End = point2Start + secondDirection * extensionLength * subDirection + firstDirection * (extensionLength / 2f) * subDirection; Gizmos.DrawLine(point2Start, point2End); Gizmos.DrawSphere(point2End, extensionLength / 8f); } }
protected override bool DetectSetup() { if (lid == null || body == null) { return(false); } finalDirection = (direction == Direction.autodetect) ? DetectDirection() : direction; if (finalDirection == Direction.autodetect) { return(false); } Bounds lidBounds = VRTK_SharedMethods.GetBounds(lid.transform, transform); // determin sub-direction depending on handle if (handle) { Bounds handleBounds = VRTK_SharedMethods.GetBounds(handle.transform, transform); switch (finalDirection) { case Direction.x: subDirection = (handleBounds.center.x > lidBounds.center.x) ? -1 : 1; break; case Direction.y: subDirection = (handleBounds.center.y > lidBounds.center.y) ? -1 : 1; break; case Direction.z: subDirection = (handleBounds.center.z > lidBounds.center.z) ? -1 : 1; break; } // handle should be outside lid hierarchy, otherwise anchor-by-bounds calculation is off if (handle.transform.IsChildOf(lid.transform)) { return(false); } } else { subDirection = -1; } if (lidJointCreated) { lidJoint.useLimits = true; lidJoint.enableCollision = true; JointLimits limits = lidJoint.limits; switch (finalDirection) { case Direction.x: lidJoint.anchor = new Vector3(subDirection * lidBounds.extents.x, 0, 0); lidJoint.axis = new Vector3(0, 0, 1); if (subDirection > 0) { limits.min = -maxAngle; limits.max = minAngle; } else { limits.min = minAngle; limits.max = maxAngle; } break; case Direction.y: lidJoint.anchor = new Vector3(0, subDirection * lidBounds.extents.y, 0); lidJoint.axis = new Vector3(0, 1, 0); if (subDirection > 0) { limits.min = -maxAngle; limits.max = minAngle; } else { limits.min = minAngle; limits.max = maxAngle; } break; case Direction.z: lidJoint.anchor = new Vector3(0, 0, subDirection * lidBounds.extents.z); lidJoint.axis = new Vector3(1, 0, 0); if (subDirection < 0) { limits.min = -maxAngle; limits.max = minAngle; } else { limits.min = minAngle; limits.max = maxAngle; } break; } lidJoint.limits = limits; } return(true); }