AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
LayerMaskExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System.Text;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity
8 {
12  public static class LayerMaskExtensions
13  {
14  public const int LayerCount = 32;
15 
16  private static string[] layerMaskNames;
17  public static string[] LayerMaskNames
18  {
19  get
20  {
21  if (layerMaskNames == null)
22  {
23  layerMaskNames = new string[LayerCount];
24  for (int layer = 0; layer < LayerCount; ++layer)
25  {
26  layerMaskNames[layer] = LayerMask.LayerToName(layer);
27  }
28  }
29 
30  return layerMaskNames;
31  }
32  }
33 
34  public static string GetDisplayString(this LayerMask layerMask)
35  {
36  StringBuilder stringBuilder = null;
37  for (int layer = 0; layer < LayerCount; ++layer)
38  {
39  if ((layerMask & (1 << layer)) != 0)
40  {
41  if (stringBuilder == null)
42  {
43  stringBuilder = new StringBuilder();
44  }
45  else
46  {
47  stringBuilder.Append(" | ");
48  }
49 
50  stringBuilder.Append(LayerMaskNames[layer]);
51  }
52  }
53 
54  return stringBuilder == null ? "None" : stringBuilder.ToString();
55  }
56  }
57 }
static string GetDisplayString(this LayerMask layerMask)
Extensions for the UnityEngine.LayerMask class.