Created
June 5, 2024 14:02
-
-
Save hariedo/10fa553a76bb204b0613bd3b258cf23f to your computer and use it in GitHub Desktop.
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
// Unity LayerMask is castable to a 32bit int bit field. | |
// Add some extension methods to make it easier and more readable to | |
// determine if a given layer or object is within the bits of a mask. | |
public static bool Contains(this LayerMask mask, int layer) | |
{ | |
return (0 != (mask & (1 << layer))); | |
} | |
public static bool Contains(this LayerMask mask, GameObject gob) | |
{ | |
if (gob == null) | |
return false; | |
return (0 != (mask & (1 << gob.layer))); | |
} | |
public static bool Contains(this LayerMask mask, Component component) | |
{ | |
if (component == null) | |
return false; | |
return (0 != (mask & (1 << component.gameObject.layer))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment