-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adder LayerMask and Improvements to TagLayerManager
- Loading branch information
1 parent
ce8727a
commit 6685502
Showing
2 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
namespace Prowl.Runtime; | ||
|
||
public class LayerMask | ||
{ | ||
private int mask; | ||
|
||
public LayerMask() | ||
{ | ||
mask = 0; | ||
} | ||
|
||
public void AddLayer(string layer) | ||
{ | ||
int layerIndex = TagLayerManager.GetLayerIndex(layer); | ||
mask |= 1 << layerIndex; | ||
} | ||
|
||
public void RemoveLayer(string layer) | ||
{ | ||
int layerIndex = TagLayerManager.GetLayerIndex(layer); | ||
if (layerIndex != -1) | ||
mask &= ~(1 << layerIndex); | ||
} | ||
|
||
public bool Contains(string layer) | ||
{ | ||
int layerIndex = TagLayerManager.GetLayerIndex(layer); | ||
return layerIndex != -1 && ((mask >> layerIndex) & 1) != 0; | ||
} | ||
|
||
public bool Intersects(LayerMask other) | ||
{ | ||
return (mask & other.mask) != 0; | ||
} | ||
|
||
public static implicit operator int(LayerMask mask) | ||
{ | ||
return mask.mask; | ||
} | ||
|
||
public static LayerMask operator |(LayerMask mask1, LayerMask mask2) | ||
{ | ||
LayerMask result = new LayerMask(); | ||
result.mask = mask1.mask | mask2.mask; | ||
return result; | ||
} | ||
|
||
public static LayerMask operator &(LayerMask mask1, LayerMask mask2) | ||
{ | ||
LayerMask result = new LayerMask(); | ||
result.mask = mask1.mask & mask2.mask; | ||
return result; | ||
} | ||
} |
This file contains 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