private SpringJoint Attach(PipePort pipe, Vector3 anchor, Vector3 connectedAnchor) { if (parentBody == null) { return(null); } SpringJoint springJoint = parentBody.gameObject.AddComponent <SpringJoint>(); springJoint.anchor = parentBody.transform.InverseTransformPoint(anchor); springJoint.autoConfigureConnectedAnchor = false; springJoint.damper = 0f; springJoint.tolerance = 0.025f; Rigidbody rigidbody = pipe.parentBody; if (rigidbody != null) { springJoint.connectedBody = rigidbody; springJoint.connectedAnchor = rigidbody.transform.InverseTransformPoint(connectedAnchor); springJoint.enableCollision = true; } else { springJoint.connectedAnchor = connectedAnchor; } return(springJoint); }
public void ScanAndConnect() { PipePort pipePort = Scan(); if (pipePort != null && pipePort != ignorePipe) { ConnectPipe(pipePort); } }
private void FixedUpdate() { if (parentBody == null || !connectable) { return; } bool flag = GrabManager.IsGrabbedAny(parentBody.gameObject); if (flag && connectedPipe == null) { PipePort pipePort = Scan(); if (pipePort != null && pipePort != ignorePipe) { ConnectPipe(pipePort); return; } } if (!flag) { ignorePipe = null; } if (!(connectedPipe != null) || !isMaster) { return; } Vector3 position = base.transform.position; if (position.y < -40f && springIn != null) { DisconnectPipe(); return; } if (breakableIn > 0f) { ApplyJointForce(loose: false, Apply: false); breakableIn -= Time.fixedDeltaTime; return; } bool loose = flag || (connectedPipe.parentBody != null && GrabManager.IsGrabbedAny(connectedPipe.parentBody.gameObject)); ApplyJointForce(loose, Apply: false); float magnitude = (base.transform.position - connectedPipe.transform.position).magnitude; if (springIn != null && magnitude > breakTreshold) { DisconnectPipe(); } }
public bool ConnectPipe(PipePort other) { connectedPipe = other; other.connectedPipe = this; isMaster = true; connectedPipe.isMaster = false; springIn = Attach(other, base.transform.position + bendArm * base.transform.forward, connectedPipe.transform.position - (bendArm + tensionDistance) * connectedPipe.transform.forward); springCenter = Attach(other, base.transform.position, connectedPipe.transform.position); tensionPhase = 0.5f; ApplyJointForce(loose: false, Apply: true); SteamSystem.Recalculate(node); SteamSystem.Recalculate(other.node); breakableIn = breakDelay; other.breakableIn = breakDelay; return(true); }
public void DisconnectPipe() { PipePort pipePort = connectedPipe; Object.Destroy(springIn); Object.Destroy(springCenter); connectedPipe.ignorePipe = this; ignorePipe = connectedPipe; connectedPipe = null; if (pipePort.springIn != null) { Object.Destroy(pipePort.springIn); Object.Destroy(pipePort.springCenter); } pipePort.connectedPipe = null; SteamSystem.Recalculate(node); SteamSystem.Recalculate(pipePort.node); }
private PipePort Scan() { float a = 0.5f; float a2 = 0.5f; Vector3 position = base.transform.position; Vector3 lhs = -base.transform.forward; PipePort pipePort = null; float num = 0f; List <PipePort> list = GetList(!isMale); for (int i = 0; i < list.Count; i++) { PipePort pipePort2 = list[i]; float num2 = Mathf.InverseLerp(a, 0f, (position - pipePort2.transform.position).magnitude); float num3 = Mathf.InverseLerp(a2, 1f, Vector3.Dot(lhs, pipePort2.transform.forward)); float num4 = num2 * num3; if (num < num4) { num = num4; pipePort = pipePort2; } } return((!(num > 0.1f)) ? null : pipePort); }