PhysicsMask
struct in
Unity.U2D.Physics
Suggest a change
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Close
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Close
Description
A 64-bit mask, effectively 64 flags. The default enumerator will iterate all the bits that are set (1).
// Get the physics mask for the "Car" layer, then get another mask for the
// layers the object should collide with.
using UnityEngine;
using Unity.U2D.Physics;
public class PhysicsMaskExample : MonoBehaviour
{
void Start()
{
PhysicsMask objectLayer = PhysicsLayers.GetLayerMask("Car");
PhysicsMask contactLayer = PhysicsLayers.GetLayerMask("Walls");
PhysicsShape.ContactFilter myContactFilter = new PhysicsShape.ContactFilter
{
categories = objectLayer,
contacts = contactLayer
};
}
}
Static Properties
| Property |
Description |
| All |
All 64 bits set (1) in the PhysicsMask.
|
| None |
No bits set in the PhysicsMask, effectively zero.
|
| One |
Bit #0 set (1) in the PhysicsMask. The remaining bits are reset (0).
|
Properties
| Property |
Description |
| bitMask |
A 64-bit mask, effectively 64 flags.
|
| resetBits |
Gets an enumerable group of bits that are currently reset (0).
The bits are returned in ascending bit-index order.
This uses ResetBitIterator.
|
| setBits |
Gets an enumerable group of bits that are currently set (1).
The bits are returned in ascending bit-index order.
This uses SetBitIterator.
|
Constructors
| Constructor |
Description |
| PhysicsMask |
Create a PhysicsMask by specifying multiple bits to set (1).
|
Public Methods
| Method |
Description |
| AreAnyBitsSet |
Checks if any of the provided PhysicsMask set bits are also set in this PhysicsMask.
|
| AreBitsSet |
Checks if all the provided PhysicsMask set bits are also set in this PhysicsMask.
|
| IsBitSet |
Is the specified bit set.
|
| ResetBit |
Reset (0) the specified bit.
|
| SetBit |
Set (1) the specified bit.
|
| ToLayerMask |
Convert the lower 32-bits of the 64-bit mask to the 32-bit LayerMask.
A LayerMask is only 32-bits wide so the upper 32-bits of the PhysicsMask will be ignored.
|
Operators
| Operator |
Description |
| operator & |
Bitwise AND operator for PhysicsMask.
|
| operator ^ |
Bitwise XOR operator for PhysicsMask.
|
| operator << |
Bitwise LEFT-SHIFT operator for PhysicsMask.
|
| operator >> |
Bitwise RIGHT-SHIFT operator for PhysicsMask.
|
| operator | |
Bitwise OR operator for PhysicsMask.
|
| operator ~ |
Bitwise COMPLEMENT operator for PhysicsMask.
|