public void Connect(GameObject jointGameObject, JointPoint jointPoint, bool sender = true) { if (!IsFree || jointPoint == null) { return; } IsFree = false; _connectedGameObject = jointGameObject; IWrapperAware wrapperAware = _connectedGameObject.GetComponentInChildren<IWrapperAware>(); if (wrapperAware != null) { _connectedWrapper = wrapperAware.Wrapper(); JointBehaviour.AddConnectedJoint(_connectedWrapper, jointPoint.JointBehaviour); } if (sender) { var jointConnectedBody = _connectedGameObject.GetComponent<Rigidbody>(); if (jointConnectedBody != null && !jointConnectedBody.isKinematic) { _fixedJoint = JointBehaviour.gameObject.AddComponent<FixedJoint>(); _fixedJoint.connectedBody = jointConnectedBody; _fixedJoint.breakForce = 600f; _fixedJoint.breakTorque = 600f; } } ConnectedJointPoint = jointPoint; ConnectedJointPoint.Connect(JointBehaviour.gameObject, this, false); }
private void OnTriggerEnter(Collider other) { JointPoint otherJointPoint = GetValidJoint(other); if (otherJointPoint == null) { return; } OnJointEnter?.Invoke(this, otherJointPoint); }
private JointPoint GetValidJoint(Collider other) { if (!IsFree) { return null; } if (IsLocked) { return null; } JointPoint otherJointPoint = other.gameObject.GetComponent<JointPoint>(); if (otherJointPoint == null) { return null; } if (!otherJointPoint.IsFree) { return null; } if (otherJointPoint.IsLocked) { return null; } if (!AcceptedKeys.Contains(otherJointPoint.Key)) { return null; } if (ProjectData.GameMode == GameMode.Edit) { if (!WorksInEditMode || !otherJointPoint.WorksInEditMode) { return null; } } if (ProjectData.GameMode == GameMode.View || ProjectData.GameMode == GameMode.Preview) { if (!WorksInViewMode || !otherJointPoint.WorksInViewMode) { return null; } } return otherJointPoint; }
private void OnTriggerExit(Collider other) { JointPoint otherJointPoint = other.GetComponent<JointPoint>(); if (otherJointPoint == null) { return; } if (ConnectedJointPoint != null && otherJointPoint != ConnectedJointPoint) { return; } if (otherJointPoint.JointBehaviour == null) { return; } Rigidbody otherBody = otherJointPoint.JointBehaviour.gameObject.GetComponent<Rigidbody>(); Rigidbody myBody = JointBehaviour.gameObject.GetComponent<Rigidbody>(); if (otherBody != null && otherBody.isKinematic && !myBody.isKinematic) { Debug.Log("Ignore kinematic trigger exit"); return; } if (JointBehaviour.IsTempConnectionCreated) { Debug.Log("Ignore IsTempConnectionCreated"); return; } Debug.Log("Joint exit!"); Disconnect(); UnLock(); OnJointExit?.Invoke(this, otherJointPoint); }