public void Recalculate() { if (_rb == null) { _colliders = new Collider[] { }; _sphereBounds = new Sphere(); _rectBounds = new Bounds(); return; } _colliders = (from c in _rb.GetComponentsInChildren <Collider>(false) where (_includeTriggers || !c.isTrigger) //TODO allow excluding colliders based on a list select c).ToArray(); if (_colliders.Length > 0) { _sphereBounds = Sphere.FromCollider(_colliders[0], _algorithm, false); _rectBounds = _colliders[0].bounds; for (int i = 1; i < _colliders.Length; i++) { _sphereBounds.Encapsulate(Sphere.FromCollider(_colliders[i], _algorithm, false)); _rectBounds.Encapsulate(_colliders[i].bounds); } } else { _sphereBounds = new Sphere(); _rectBounds = new Bounds(); } }
public static Capsule FromCollider(Collider c, BoundingSphereAlgorithm algorithm, bool local = false) { if (c is SphereCollider) { return(FromCollider(c as SphereCollider, local)); } else if (c is CapsuleCollider) { return(FromCollider(c as CapsuleCollider, local)); } else { var s = Sphere.FromCollider(c, algorithm, local); return(new Capsule(s.Center, s.Center, s.Radius)); } }
/// <summary> /// Attempts to calculate geometry for a collider. Not tested yet. /// </summary> /// <param name="c"></param> /// <returns></returns> public static IPhysicsGeom GetGeom(this Collider c, BoundingSphereAlgorithm algorithm, bool local = false) { if (c == null) { return(null); } if (c is CharacterController) { return(Capsule.FromCollider(c as CharacterController, local)); } if (c is CapsuleCollider) { return(Capsule.FromCollider(c as CapsuleCollider, local)); } else if (c is BoxCollider) { return(Box.FromCollider(c as BoxCollider, local)); } else if (c is SphereCollider) { return(Sphere.FromCollider(c as SphereCollider, local)); } else if (algorithm != BoundingSphereAlgorithm.FromBounds && c is MeshCollider) { if (local) { return(Sphere.FromMesh((c as MeshCollider).sharedMesh, algorithm)); } else { return(Sphere.FromMesh((c as MeshCollider).sharedMesh, algorithm, Trans.GetGlobal(c.transform))); } } else { //otherwise just return bounds as AABBox return(AABBox.FromCollider(c, local)); } }
public static Sphere GetLocalBoundingSphere(this Collider c, BoundingSphereAlgorithm algorithm) { return(Sphere.FromCollider(c, algorithm, true)); }
public static Sphere GetLocalBoundingSphere(this Collider c) { return(Sphere.FromCollider(c, GeomUtil.DefaultBoundingSphereAlgorithm, true)); }
public static Sphere GetGlobalBoundingSphere(this Collider c, BoundingSphereAlgorithm algorithm) { return(Sphere.FromCollider(c, algorithm, false)); }