-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGridLayer.cs
More file actions
60 lines (51 loc) · 1.21 KB
/
GridLayer.cs
File metadata and controls
60 lines (51 loc) · 1.21 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
58
59
60
using UnityEngine;
using System.Collections;
namespace BlkEdit
{
public class GridLayer
{
public GridLayer (Uzu.VectorI2 dimensions)
{
_dimensions = dimensions;
int totalCount = Uzu.VectorI2.ElementProduct (_dimensions);
_states = new bool[totalCount];
_colors = new Color32[totalCount];
}
public bool IsSet (Uzu.VectorI2 coord)
{
int idx = CoordToIndex (_dimensions, coord);
return _states [idx];
}
public void Unset (Uzu.VectorI2 coord)
{
int idx = CoordToIndex (_dimensions, coord);
_states [idx] = false;
}
public Color32 GetColor (Uzu.VectorI2 coord)
{
int idx = CoordToIndex (_dimensions, coord);
return _colors [idx];
}
public void SetColor (Uzu.VectorI2 coord, Color32 color)
{
int idx = CoordToIndex (_dimensions, coord);
_states [idx] = true;
_colors [idx] = color;
}
public void Clear ()
{
for (int i = 0; i < _states.Length; i++) {
_states [i] = false;
}
}
#region Implementation.
private Uzu.VectorI2 _dimensions;
private bool[] _states;
private Color32[] _colors;
private static int CoordToIndex (Uzu.VectorI2 dimensions, Uzu.VectorI2 coord)
{
return coord.y * dimensions.x + coord.x;
}
#endregion
};
}