-
Notifications
You must be signed in to change notification settings - Fork 0
/
LayerExtensions.cs
41 lines (37 loc) · 977 Bytes
/
LayerExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class LayerExtensions
{
public static int ToLayer(this LayerMask layerMask)
{
int layerNumber = 0;
int layer = layerMask.value;
while (layer > 0)
{
layer = layer >> 1;
layerNumber++;
}
return layerNumber - 1;
}
public static LayerMask ToLayerMask(this int indexLayer)
{
return 1 << indexLayer;
}
public static LayerMask GetPhysicsLayerMask(this int currentLayer)
{
int finalMask = 0;
for (int i = 0; i < 32; i++)
{
if (!Physics.GetIgnoreLayerCollision(currentLayer, i))
{
finalMask = finalMask | (1 << i);
}
}
return finalMask;
}
public static bool Contains(this LayerMask layerMask, int layer)
{
return layerMask == (layerMask | (1 << layer));
}
}