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 pathMapperEditor.cs
More file actions
154 lines (123 loc) · 3.6 KB
/
MapperEditor.cs
File metadata and controls
154 lines (123 loc) · 3.6 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
143
144
145
146
147
148
149
150
151
152
153
154
#if !UNITY_WEBPLAYER
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;
using Common;
namespace EditorArea {
[CustomEditor(typeof(Mapper))]
public class MapperEditor : Editor {
public static Cell[][] grid;
//
public static bool editGrid = false, didUpdate = false;
//
private Mapper mapper;
private MapperEditorDrawer drawer;
public void OnSceneGUI () {
// Update drawer
if (drawer != null)
drawer.editGrid = editGrid;
// Stop if needed
if (!editGrid) {
didUpdate = false;
return;
}
// Create grid
if (grid == null || grid.Length != MapperWindowEditor.gridSize) {
grid = new Cell[MapperWindowEditor.gridSize][];
for (int i = 0; i < MapperWindowEditor.gridSize; i++)
grid [i] = new Cell[MapperWindowEditor.gridSize];
}
// Prepare holders
if (mapper == null) {
mapper = (Mapper)target;
}
if (drawer == null) {
drawer = mapper.gameObject.GetComponent<MapperEditorDrawer> ();
}
drawer.editingGrid = grid;
// Update Scene
if (!didUpdate) {
mapper.ComputeTileSize (SpaceState.Editor, mapper.collider.bounds.min, mapper.collider.bounds.max, MapperWindowEditor.gridSize, MapperWindowEditor.gridSize);
drawer.tileSize.Set (SpaceState.Editor.tileSize.x, SpaceState.Editor.tileSize.y);
drawer.zero.Set (SpaceState.Editor.floorMin.x, SpaceState.Editor.floorMin.z);
didUpdate = true;
}
// Raycast
Event current = Event.current;
if (current != null && EventType.KeyDown == current.type) {
Ray ray = HandleUtility.GUIPointToWorldRay (current.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer ("Floor"))) {
if (hit.transform.CompareTag ("Floor")) {
Vector2 pos = new Vector2 ((hit.point.x - hit.collider.bounds.min.x) / SpaceState.Editor.tileSize.x, (hit.point.z - hit.collider.bounds.min.x) / SpaceState.Editor.tileSize.y);
Cell c = grid [(int)pos.x] [(int)pos.y];
if (c == null) {
c = new Cell ();
grid [(int)pos.x] [(int)pos.y] = c;
}
switch (current.keyCode) {
case KeyCode.Alpha0:
grid [(int)pos.x] [(int)pos.y] = null;
break;
case KeyCode.Alpha1:
c.safe = true;
break;
case KeyCode.Alpha2:
c.blocked = true;
break;
case KeyCode.Alpha3:
c.noisy = true;
break;
case KeyCode.Alpha4:
c.waypoint = true;
break;
case KeyCode.U:
c.cluster = 0;
break;
case KeyCode.Alpha6:
c.cluster |= 1;
break;
case KeyCode.Alpha7:
c.cluster |= 2;
break;
case KeyCode.Alpha8:
c.cluster |= 4;
break;
case KeyCode.Alpha9:
c.cluster |= 8;
break;
case KeyCode.Keypad4:
c.cluster |= 8;
break;
case KeyCode.Keypad5:
c.cluster |= 16;
break;
case KeyCode.Keypad6:
c.cluster |= 32;
break;
case KeyCode.Keypad7:
c.cluster |= 64;
break;
case KeyCode.Keypad8:
c.cluster |= 128;
break;
case KeyCode.Keypad9:
c.cluster |= 256;
break;
}
SceneView.RepaintAll ();
}
}
}
} // OnSceneGui
} // Class
} // NS
#endif