This repository was archived by the owner on Oct 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMapperEditorDrawer.cs
More file actions
142 lines (129 loc) · 4.26 KB
/
MapperEditorDrawer.cs
File metadata and controls
142 lines (129 loc) · 4.26 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#if !UNITY_WEBPLAYER
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
using Common;
namespace EditorArea {
public class MapperEditorDrawer : MonoBehaviour {
public Cell[][][] fullMap;
public float[][] seenNeverSeen;
public List<Node> rrtMap;
public Dictionary<Path, bool> paths = new Dictionary<Path, bool> ();
public int[,] heatMap;
public int[][,] heatMap3d;
public float heatMapMax = 0, seenNeverSeenMax;
public int[] heatMapMax3d;
public int timeSlice;
public Vector2 zero = new Vector2 ();
public Vector2 tileSize = new Vector2 ();
public bool drawMap = true, drawNeverSeen = false, drawHeatMap = true, drawPath = false, editGrid = false, drawFoVOnly = false;
public Cell[][] editingGrid;
// Fixed values
private Color orange = new Color (1.0f, 0.64f, 0f, 1f), transparent = new Color (1f, 1f, 1f, 0f);
public void Start () {
hideFlags = HideFlags.HideInInspector;
}
public void OnDrawGizmos () {
// We need 2 if blocks since we are using 2 different variables to poke the data from
if (editGrid && editingGrid != null) {
for (int x = 0; x < editingGrid.Length; x++)
for (int y = 0; y < editingGrid[x].Length; y++) {
Cell c = editingGrid [x] [y];
if (drawFoVOnly) {
if (c != null && c.seen)
Gizmos.color = orange;
else
Gizmos.color = transparent;
} else {
if (c == null)
Gizmos.color = Color.gray;
else if (c.safe)
Gizmos.color = Color.blue;
else if (c.blocked)
Gizmos.color = Color.red;
else if (c.seen)
Gizmos.color = orange;
else if (c.noisy)
Gizmos.color = Color.yellow;
else if (c.waypoint)
Gizmos.color = Color.cyan;
else if (c.cluster > 0)
Gizmos.color = Color.white;
else
Gizmos.color = Color.gray;
}
Gizmos.DrawCube (new Vector3
(x * tileSize.x + zero.x + tileSize.x / 2f,
0.1f,
y * tileSize.y + zero.y + tileSize.y / 2f),
new Vector3
(tileSize.x - tileSize.x * 0.05f,
0.0f,
tileSize.y - tileSize.y * 0.05f));
}
} else if (drawMap && fullMap != null) {
for (int x = 0; x < fullMap[timeSlice].Length; x++)
for (int y = 0; y < fullMap[timeSlice][x].Length; y++) {
Cell c = fullMap [timeSlice] [x] [y];
if (drawHeatMap) {
if (heatMap != null)
Gizmos.color = Color.Lerp (Color.white, Color.black, (float)heatMap [x, y] / (heatMapMax * 6f / 8f));
else if (heatMap3d != null)
Gizmos.color = Color.Lerp (Color.white, Color.black, heatMapMax3d [timeSlice] != 0 ? (float)heatMap3d [timeSlice] [x, y] / (float)heatMapMax3d [timeSlice] : 0f);
} else {
if (drawFoVOnly) {
if (c.seen)
Gizmos.color = orange;
else
Gizmos.color = transparent;
} else {
if (c.safe)
Gizmos.color = Color.blue;
else if (c.blocked)
Gizmos.color = Color.red;
else if (c.seen)
Gizmos.color = orange;
else if (c.noisy)
Gizmos.color = Color.yellow;
else if (c.waypoint)
Gizmos.color = Color.cyan;
else if (c.cluster > 0)
Gizmos.color = Color.white;
else if (drawNeverSeen)
Gizmos.color = Color.Lerp (Color.green, Color.magenta, seenNeverSeen [x] [y] / (seenNeverSeenMax * 3f / 8f));
else
Gizmos.color = Color.green;
}
}
Gizmos.DrawCube (new Vector3
(x * tileSize.x + zero.x + tileSize.x / 2f,
0.1f,
y * tileSize.y + zero.y + tileSize.y / 2f),
new Vector3
(tileSize.x - tileSize.x * 0.05f,
0.0f,
tileSize.y - tileSize.y * 0.05f));
}
}
// All Paths drawning
if (drawPath) {
Gizmos.color = Color.blue;
foreach (KeyValuePair<Path, bool> kv in paths)
if (kv.Value) {
Gizmos.color = kv.Key.color;
foreach (Node n in kv.Key.points)
if (n.parent != null)
Gizmos.DrawLine (new Vector3
((n.x * tileSize.x + zero.x),
0.1f,
(n.y * tileSize.x + zero.y)),
new Vector3
((n.parent.x * tileSize.y + zero.x),
0.1f,
(n.parent.y * tileSize.y + zero.y)));
}
}
}
}
}
#endif