Created
January 22, 2019 16:24
-
-
Save robertwahler/884339ea639784275fbba1a611c22499 to your computer and use it in GitHub Desktop.
Non allocating, lazy loaded, Unity Physics.OverlapSphere
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Collider cache for non allocating physics calls. Lazy loaded. | |
/// </summary> | |
/// <example> | |
/// Usage | |
/// <code> | |
/// float radius = 0.2f; | |
/// int colliderCount = Physics.OverlapSphereNonAlloc(transform.position, radius: radius, results: ColliderCache); | |
/// for (int i = 0; i<colliderCount; i++) { | |
/// ... | |
/// } | |
/// </code> | |
/// </example> | |
protected Collider[] ColliderCache { | |
get { | |
if (colliderCache == null) { | |
colliderCache = new Collider[colliderCacheSize]; | |
} | |
return colliderCache; | |
} | |
} | |
protected int colliderCacheSize = 32; | |
private Collider[] colliderCache; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment