// Demolish cluster IEnumerator DelayedClusterCor(RayfireRigid rigid, Collider coll) { // Wait life time yield return(new WaitForSeconds(delay)); // Activate if (rigid != null && coll != null) { RFDemolitionCluster.DemolishConnectedCluster(rigid, new[] { coll }); } }
/// ///////////////////////////////////////////////////////// /// Activation /// ///////////////////////////////////////////////////////// // Check for RayFire Rigid component activation void ActivationCheck(Collider coll) { // Get rigid from collider or rigid body RayfireRigid rigid = coll.attachedRigidbody == null ? coll.GetComponent <RayfireRigid>() : coll.attachedRigidbody.GetComponent <RayfireRigid>(); // Has no rigid if (rigid == null) { return; } // Activation if (rigid.activation.byActivator == true) { if (rigid.simulationType == SimType.Inactive || rigid.simulationType == SimType.Kinematic) { if (delay <= 0) { rigid.Activate(); } else { StartCoroutine(DelayedActivationCor(rigid)); } } } // Connected cluster one fragment detach if (rigid.objectType == ObjectType.ConnectedCluster) { if (demolishCluster == true) { if (delay <= 0) { RFDemolitionCluster.DemolishConnectedCluster(rigid, new[] { coll }); } else { StartCoroutine(DelayedClusterCor(rigid, coll)); } } } }
// Impact hit to rigid bodies. Activated inactive, detach clusters void ImpactHit(RayfireRigid rigid, RaycastHit hit, Vector3 impactPoint, Vector3 shootVector) { // Prepare impact list List <Rigidbody> impactRbList = new List <Rigidbody>(); // Hit object Impact activation and detach before impact force if (radius == 0) { // Inactive Activation if (rigid.objectType == ObjectType.Mesh) { if (rigid.simulationType == SimType.Inactive || rigid.simulationType == SimType.Kinematic) { if (rigid.activation.byImpact == true) { rigid.Activate(); } } } // Connected cluster one fragment detach if (rigid.objectType == ObjectType.ConnectedCluster) { if (demolishCluster == true) { RFDemolitionCluster.DemolishConnectedCluster(rigid, new[] { hit.collider }); } } // Collect for impact impactRbList.Add(hit.collider.attachedRigidbody); } // Group by radius Impact activation and detach before impact force if (radius > 0) { // Get all colliders impactColliders = null; impactColliders = Physics.OverlapSphere(impactPoint, radius, mask); // TODO tag filter if (tagFilter != untagged) { // && colliders[i].CompareTag (tagFilter) == false) } // No colliders. Stop if (impactColliders == null) { return; } // Connected cluster group detach first, check for rigids in range next if (rigid.objectType == ObjectType.ConnectedCluster) { if (demolishCluster == true) { RFDemolitionCluster.DemolishConnectedCluster(rigid, impactColliders); } } // Collect all rigid bodies in range RayfireRigid scr; List <RayfireRigid> impactRigidList = new List <RayfireRigid>(); for (int i = 0; i < impactColliders.Length; i++) { // Get rigid from collider or rigid body scr = impactColliders[i].attachedRigidbody == null ? impactColliders[i].GetComponent <RayfireRigid>() : impactColliders[i].attachedRigidbody.transform.GetComponent <RayfireRigid>(); // Collect uniq rigids in radius if (scr != null) { if (impactRigidList.Contains(scr) == false) { impactRigidList.Add(scr); } } // Collect RigidBodies without rigid script else { if (affectRigidBodies == true) { if (impactColliders[i].attachedRigidbody == null) { if (impactRbList.Contains(impactColliders[i].attachedRigidbody) == false) { impactRbList.Add(impactColliders[i].attachedRigidbody); } } } } } // Group Activation first for (int i = 0; i < impactRigidList.Count; i++) { if (impactRigidList[i].activation.byImpact == true) { if (impactRigidList[i].simulationType == SimType.Inactive || impactRigidList[i].simulationType == SimType.Kinematic) { impactRigidList[i].Activate(); } } } // Collect rigid body from rigid components if (strength > 0) { for (int i = 0; i < impactRigidList.Count; i++) { // Skip inactive objects if (impactRigidList[i].simulationType == SimType.Inactive && affectInactive == false) { continue; } // Collect impactRbList.Add(impactRigidList[i].physics.rigidBody); } } } // NO Strength if (strength == 0) { return; } // No rigid bodies if (impactRbList.Count == 0) { return; } // Apply force for (int i = 0; i < impactRbList.Count; i++) { // Skip static and kinematik objects if (impactRbList[i] == null || impactRbList[i].isKinematic == true) { continue; } // Add force impactRbList[i].AddForceAtPosition(shootVector * strength, impactPoint, ForceMode.VelocityChange); } }