private bool Connect(HoseSocket scan) { connectedSocket = scan; springIn = Attach(scan, alignmentTransform.position + torque * alignmentTransform.forward, connectedSocket.transform.position + (torque + tensionDistance) * connectedSocket.transform.forward); springOut = Attach(scan, alignmentTransform.position - torque * alignmentTransform.forward, connectedSocket.transform.position - (torque + tensionDistance / 2f) * connectedSocket.transform.forward); return(true); }
private void Disconnect() { Object.Destroy(springIn); Object.Destroy(springOut); ignoreSocketConnect = connectedSocket; connectedSocket = null; }
private void Start() { alignmentTransform = base.transform; startSocket = connectedSocket; if (startSocket != null) { Connect(connectedSocket); } }
public void ApplyState(NetStream state) { uint num = state.ReadNetId(); HoseSocket hoseSocket = (num == 0) ? null : HoseSocket.FindById(num); if (connectedSocket != hoseSocket) { if (connectedSocket != null) { Disconnect(); } if (hoseSocket != null) { Connect(hoseSocket); } } }
public static HoseSocket Scan(Vector3 pos) { HoseSocket result = null; float num = 0f; for (int i = 0; i < all.Count; i++) { HoseSocket hoseSocket = all[i]; float num2 = 1f - (pos - hoseSocket.transform.position).magnitude / hoseSocket.radius; if (!(num2 < 0f)) { num2 = Mathf.Pow(num2, hoseSocket.power); if (num < num2) { num = num2; result = hoseSocket; } } } return(result); }
private SpringJoint Attach(HoseSocket socket, Vector3 anchor, Vector3 connectedAnchor) { SpringJoint springJoint = base.gameObject.AddComponent <SpringJoint>(); springJoint.anchor = base.transform.InverseTransformPoint(anchor); springJoint.autoConfigureConnectedAnchor = false; Rigidbody componentInParent = socket.GetComponentInParent <Rigidbody>(); if (componentInParent != null) { springJoint.connectedBody = componentInParent; springJoint.connectedAnchor = componentInParent.transform.InverseTransformPoint(connectedAnchor); springJoint.enableCollision = true; } else { springJoint.connectedAnchor = connectedAnchor; } springJoint.spring = spring; springJoint.damper = damper; return(springJoint); }
private void FixedUpdate() { if (ReplayRecorder.isPlaying || NetGame.isClient) { return; } bool flag = false; for (int i = 0; i < grablist.Length; i++) { if (GrabManager.IsGrabbedAny(grablist[i])) { flag = true; } } if (flag && connectedSocket == null) { HoseSocket hoseSocket = HoseSocket.Scan(alignmentTransform.position); if (hoseSocket != null && hoseSocket != ignoreSocketConnect) { if (Connect(hoseSocket)) { canBreak = false; breakableIn = breakDelay; return; } Collider[] array = Physics.OverlapSphere(base.transform.position, 5f); for (int j = 0; j < array.Length; j++) { Rigidbody componentInParent = array[j].GetComponentInParent <Rigidbody>(); if (componentInParent != null && !componentInParent.isKinematic) { componentInParent.AddExplosionForce(20000f, base.transform.position, 5f); Human componentInParent2 = componentInParent.GetComponentInParent <Human>(); if (componentInParent2 != null) { componentInParent2.MakeUnconscious(); } } } SendPlug(PlugEventType.Short); } } if (!flag) { ignoreSocketConnect = null; canBreak = true; } if (breakableIn > 0f) { breakableIn -= Time.fixedDeltaTime; } else if (connectedSocket != null) { springIn.spring = ((!flag) ? spring : (spring / 2f)); springOut.spring = ((!flag) ? spring : (spring / 2f)); float num = (alignmentTransform.position - alignmentTransform.forward * dispacementTolerance - connectedSocket.transform.position).magnitude - dispacementTolerance; if (springIn != null && springOut != null && num > breakTreshold) { Disconnect(); } } }