AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
LayerExtensions.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 UnityEngine;
5 
6 namespace HoloToolkit.Unity
7 {
8  public static class LayerExtensions
9  {
10  private const int InvalidLayer = -1;
11 
12  #region Local layers
13  private static int defaultLayer = InvalidLayer;
14  private static int surfaceLayer = InvalidLayer;
15  private static int interactionLayer = InvalidLayer;
16  private static int activationLayer = InvalidLayer;
17  #endregion
18 
19  public static int Default
20  {
21  get
22  {
23  return GetLayerNumber(ref defaultLayer, "Default");
24  }
25  }
26 
27  public static int Surface
28  {
29  get
30  {
31  return GetLayerNumber(ref surfaceLayer, "SR");
32  }
33  }
34  public static int Interaction
35  {
36  get
37  {
38  return GetLayerNumber(ref interactionLayer, "Interaction");
39  }
40  }
41 
42  public static int Activation
43  {
44  get
45  {
46  return GetLayerNumber(ref activationLayer, "Activation");
47  }
48  }
49 
56  public static int FindLayerListIndex(this int layer, LayerMask[] layerMasks)
57  {
58  var i = 0;
59  for (int j = 0; j < layerMasks.Length; j++)
60  {
61  if (layer.IsInLayerMask(layerMasks[i]))
62  {
63  return i;
64  }
65 
66  i++;
67  }
68  return -1;
69  }
70 
75  public static bool IsInLayerMask(this int layer, int layerMask)
76  {
77  return ((1 << layer) & layerMask) != 0;
78  }
79 
84  public static int Combine(this LayerMask[] layerMaskList)
85  {
86  int combinedLayerMask = 0;
87  for (int i = 0; i < layerMaskList.Length; i++)
88  {
89  combinedLayerMask = combinedLayerMask | layerMaskList[i].value;
90  }
91  return combinedLayerMask;
92  }
93 
94  public static LayerMask ToMask(int layer)
95  {
96  return 1 << layer;
97  }
98 
99  private static int GetLayerNumber(ref int cache, string layerName)
100  {
101  if (cache == InvalidLayer)
102  {
103  cache = LayerMask.NameToLayer(layerName);
104  }
105  return cache;
106  }
107  }
108 }
static int FindLayerListIndex(this int layer, LayerMask[] layerMasks)
Look through the layerMaskList and find the index in that list for which the supplied layer is part o...
static LayerMask ToMask(int layer)
static int Combine(this LayerMask[] layerMaskList)
Combines provided layers into a single layer mask.
static bool IsInLayerMask(this int layer, int layerMask)
Checks whether a layer is in a layer mask