Tanoda
SingleLayer.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using System;
10
11namespace Leap.Unity {
12
19 [Serializable]
20 public struct SingleLayer : IEquatable<SingleLayer> {
21 public int layerIndex;
22
23 public int layerMask {
24 get {
25 return 1 << layerIndex;
26 }
27 set {
28 if (value == 0) {
29 throw new ArgumentException("Single layer can only represent exactly one layer. The provided mask represents no layers (mask was zero).");
30 }
31
32 int newIndex = 0;
33 while ((value & 1) == 0) {
34 value = value >> 1;
35 newIndex++;
36 }
37
38 if (value != 1) {
39 throw new ArgumentException("Single layer can only represent exactly one layer. The provided mask represents more than one layer.");
40 }
41
42 layerIndex = newIndex;
43 }
44 }
45
46 public static implicit operator int(SingleLayer singleLayer) {
47 return singleLayer.layerIndex;
48 }
49
50 public static implicit operator SingleLayer(int layerIndex) {
51 SingleLayer singleLayer = new SingleLayer();
52 singleLayer.layerIndex = layerIndex;
53 return singleLayer;
54 }
55
56 public bool Equals(SingleLayer other) {
57 return this.layerIndex == other.layerIndex;
58 }
59 }
60}
An object you can use to represent a single Unity layer as a dropdown in the inspector....
Definition: SingleLayer.cs:20
bool Equals(SingleLayer other)
Definition: SingleLayer.cs:56