forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayerMaskExtensions.cs
More file actions
57 lines (50 loc) · 1.75 KB
/
LayerMaskExtensions.cs
File metadata and controls
57 lines (50 loc) · 1.75 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System.Text;
using UnityEngine;
namespace HoloToolkit.Unity
{
/// <summary>
/// Extensions for the UnityEngine.LayerMask class.
/// </summary>
public static class LayerMaskExtensions
{
public const int LayerCount = 32;
private static string[] layerMaskNames = null;
public static string[] LayerMaskNames
{
get
{
if (layerMaskNames == null)
{
LayerMaskExtensions.layerMaskNames = new string[LayerCount];
for (int layer = 0; layer < LayerCount; ++layer)
{
LayerMaskExtensions.layerMaskNames[layer] = LayerMask.LayerToName(layer);
}
}
return LayerMaskExtensions.layerMaskNames;
}
}
public static string GetDisplayString(this LayerMask layerMask)
{
StringBuilder stringBuilder = null;
for (int layer = 0; layer < LayerMaskExtensions.LayerCount; ++layer)
{
if ((layerMask & (1 << layer)) != 0)
{
if (stringBuilder == null)
{
stringBuilder = new StringBuilder();
}
else
{
stringBuilder.Append(" | ");
}
stringBuilder.Append(LayerMaskExtensions.LayerMaskNames[layer]);
}
}
return stringBuilder == null ? "None" : stringBuilder.ToString();
}
}
}