Falco Engine 3.9.0.1 (beta)
LayerMask.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Runtime.CompilerServices;
4
5namespace FalcoEngine
6{
7 public class LayerMask
8 {
9 private BitArray bitset = new BitArray(32, true);
10
11 private static readonly LayerMask all = new LayerMask();
12
16 public static LayerMask All => all;
17
23 [MethodImpl(MethodImplOptions.InternalCall)]
24 public static extern string LayerToName(int layer);
25
31 [MethodImpl(MethodImplOptions.InternalCall)]
32 public static extern int NameToLayer(string name);
33
39 public void Set(int layer, bool value)
40 {
41 if (layer < bitset.Count)
42 bitset.Set(layer, value);
43 }
44
50 public bool Get(int layer)
51 {
52 if (layer < bitset.Count)
53 return bitset.Get(layer);
54 else
55 return false;
56 }
57
62 public ulong ToULong()
63 {
64 var array = new byte[32];
65 bitset.CopyTo(array, 0);
66
67 return BitConverter.ToUInt64(array, 0);
68 }
69
74 public void FromULong(ulong value)
75 {
76 byte[] bytes = BitConverter.GetBytes(value);
77 bitset = new BitArray(bytes);
78 }
79 }
80}
static string LayerToName(int layer)
Return name of the layer
static LayerMask All
Return layer mask with all layers selected
Definition: LayerMask.cs:16
void FromULong(ulong value)
Restore layers from ulong
Definition: LayerMask.cs:74
bool Get(int layer)
Get state of the layer
Definition: LayerMask.cs:50
ulong ToULong()
Convert this layer mask to ulong
Definition: LayerMask.cs:62
void Set(int layer, bool value)
Enable or disable layer
Definition: LayerMask.cs:39
static int NameToLayer(string name)
Return layer by it's name