void OnTriggerExit(Collider other) { m_colliderVertices.Remove(other); DynamicColliderPair targetPair = null; if (m_dynamicPairMap.TryGetValue(other, out targetPair)) { m_dynamicCollidersInView.RemoveAll(x => x.collider == other); m_dynamicPairMap.Remove(other); } }
public void OnTriggerEnter(Collider other) { if (other.gameObject.layer == LayerMask.NameToLayer("LevelGeo")) { if (m_colliderVertices.ContainsKey(other)) { return; } if (other is CapsuleCollider) { CapsuleCollider newCollider = other as CapsuleCollider; ColliderVertices newVertices = new ColliderVertices(); newVertices.collider = newCollider; Vector3 diff = newCollider.transform.position - transform.position; Vector3 normal = Vector3.Cross(diff, Vector3.up); Vector3 p0 = (normal.normalized * newCollider.radius); Vector3 p1 = -p0; newVertices.vertices.Add(p0); newVertices.vertices.Add(p1); m_colliderVertices.Add(other, newVertices); if (GameObjectHelper.SearchParentsForComponent <Rigidbody>(other.gameObject) != null && GameObjectHelper.SearchParentsForComponent <OcclusionMeshStatic>(other.gameObject) == null) { DynamicColliderPair newPair = new DynamicColliderPair(); newPair.collider = other; newPair.lastPosition = other.transform.position; newPair.lastRotation = other.transform.rotation; newPair.lastScale = other.transform.lossyScale; try { m_dynamicCollidersInView.Add(newPair); m_dynamicPairMap.Add(other, newPair); } catch (Exception e) { Debug.LogWarning("Failed added collider: " + other.name); } } } if (other is BoxCollider) { BoxCollider newCollider = other as BoxCollider; ColliderVertices newVertices = new ColliderVertices(); newVertices.collider = newCollider; newVertices.vertices.Add(new Vector3(-newCollider.size.x / 2.0f, 0.0f, -newCollider.size.z / 2.0f)); newVertices.vertices.Add(new Vector3(-newCollider.size.x / 2.0f, 0.0f, newCollider.size.z / 2.0f)); newVertices.vertices.Add(new Vector3(newCollider.size.x / 2.0f, 0.0f, -newCollider.size.z / 2.0f)); newVertices.vertices.Add(new Vector3(newCollider.size.x / 2.0f, 0.0f, newCollider.size.z / 2.0f)); m_colliderVertices.Add(other, newVertices); if (GameObjectHelper.SearchParentsForComponent <Rigidbody>(other.gameObject) != null && GameObjectHelper.SearchParentsForComponent <OcclusionMeshStatic>(other.gameObject) == null) { DynamicColliderPair newPair = new DynamicColliderPair(); newPair.collider = other; newPair.lastPosition = other.transform.position; newPair.lastRotation = other.transform.rotation; newPair.lastScale = other.transform.lossyScale; try { m_dynamicCollidersInView.Add(newPair); m_dynamicPairMap.Add(other, newPair); } catch (Exception e) { Debug.LogWarning("Failed added collider: " + other.name); } } } // If this is a static light, rebuild meshes immediately as there will be no Update if (!Dynamic) { RebuildMesh(); } } }