Skip to content

Commit 6eefd04

Browse files
committed
Merge branch 'beta'
2 parents 4f54b9c + 59fdb39 commit 6eefd04

File tree

5 files changed

+25
-71
lines changed

5 files changed

+25
-71
lines changed

Assets/MapEditor/Managers/PathManager.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
public static class PathManager
77
{
8-
public static GameObject defaultPath { get; private set; }
9-
public static GameObject defaultNode { get; private set; }
10-
public static Transform pathParent { get; private set; }
8+
public static GameObject DefaultPath { get; private set; }
9+
public static GameObject DefaultNode { get; private set; }
10+
public static Transform PathParent { get; private set; }
1111

1212
public enum PathType
1313
{
@@ -24,27 +24,27 @@ public static void Init()
2424

2525
static void OnProjectLoad()
2626
{
27-
defaultPath = Resources.Load<GameObject>("Paths/Path");
28-
defaultNode = Resources.Load<GameObject>("Paths/PathNode");
29-
pathParent = GameObject.FindGameObjectWithTag("Paths").transform;
27+
DefaultPath = Resources.Load<GameObject>("Paths/Path");
28+
DefaultNode = Resources.Load<GameObject>("Paths/PathNode");
29+
PathParent = GameObject.FindGameObjectWithTag("Paths").transform;
3030
EditorApplication.update -= OnProjectLoad;
3131
}
3232

3333
public static void Spawn(PathData pathData)
3434
{
3535
Vector3 averageLocation = Vector3.zero;
3636
for (int j = 0; j < pathData.nodes.Length; j++)
37-
{
3837
averageLocation += pathData.nodes[j];
39-
}
38+
4039
averageLocation /= pathData.nodes.Length;
41-
GameObject newObject = GameObject.Instantiate(defaultPath, averageLocation + pathParent.position, Quaternion.identity, pathParent);
40+
GameObject newObject = GameObject.Instantiate(DefaultPath, averageLocation + PathParent.position, Quaternion.identity, PathParent);
41+
newObject.name = pathData.name;
4242

4343
List<GameObject> pathNodes = new List<GameObject>();
4444
for (int j = 0; j < pathData.nodes.Length; j++)
4545
{
46-
GameObject newNode = GameObject.Instantiate(defaultNode, newObject.transform);
47-
newNode.transform.position = pathData.nodes[j] + pathParent.position;
46+
GameObject newNode = GameObject.Instantiate(DefaultNode, newObject.transform);
47+
newNode.transform.position = pathData.nodes[j] + PathParent.position;
4848
pathNodes.Add(newNode);
4949
}
5050
newObject.GetComponent<PathDataHolder>().pathData = pathData;

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static GameObject Process(GameObject go, string filePath)
5555
}
5656
PrefabDataHolder prefabDataHolder = go.AddComponent<PrefabDataHolder>();
5757
prefabDataHolder.prefabData = new PrefabData() { id = AssetManager.ToID(filePath) };
58+
prefabDataHolder.Setup();
5859
return go;
5960
}
6061

@@ -107,53 +108,22 @@ private static class Coroutines
107108
public static IEnumerator SpawnPrefabs(PrefabData[] prefabs)
108109
{
109110
IsBusy = true;
110-
yield return EditorCoroutineUtility.StartCoroutineOwnerless(PreparePrefabsCoroutine(prefabs));
111111
yield return EditorCoroutineUtility.StartCoroutineOwnerless(SpawnPrefabsCoroutine(prefabs));
112112
IsBusy = false;
113113
}
114114

115-
private static IEnumerator PreparePrefabsCoroutine(PrefabData[] prefabs)
115+
public static IEnumerator ReplaceWithLoaded(PrefabDataHolder[] prefabs)
116116
{
117-
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
118-
sw.Start();
119-
120-
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
121-
for (int i = 0; i < prefabs.Length; i++)
122-
{
123-
if (sw.Elapsed.TotalSeconds > 0.1f)
124-
{
125-
sw.Restart();
126-
ProgressBarManager.DisplayIncremental("Processing Prefabs", "Loading Prefabs: " + i + " / " + prefabs.Length);
127-
yield return null;
128-
}
129-
else
130-
ProgressBarManager.AddIncrement();
131-
132-
Load(prefabs[i].id);
133-
}
134-
ProgressBarManager.Clear();
117+
IsBusy = true;
118+
yield return EditorCoroutineUtility.StartCoroutineOwnerless(ReplaceWithLoadedCoroutine(prefabs));
119+
IsBusy = false;
135120
}
136121

137-
private static IEnumerator PreparePrefabsCoroutine(PrefabDataHolder[] prefabs)
122+
public static IEnumerator ReplaceWithDefault(PrefabDataHolder[] prefabs)
138123
{
139-
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
140-
sw.Start();
141-
142-
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
143-
for (int i = 0; i < prefabs.Length; i++)
144-
{
145-
if (sw.Elapsed.TotalSeconds > 0.1f)
146-
{
147-
sw.Restart();
148-
ProgressBarManager.DisplayIncremental("Processing Prefabs", "Loading Prefabs: " + i + " / " + prefabs.Length);
149-
yield return null;
150-
}
151-
else
152-
ProgressBarManager.AddIncrement();
153-
154-
Load(prefabs[i].prefabData.id);
155-
}
156-
ProgressBarManager.Clear();
124+
IsBusy = true;
125+
yield return EditorCoroutineUtility.StartCoroutineOwnerless(ReplaceWithDefaultCoroutine(prefabs));
126+
IsBusy = false;
157127
}
158128

159129
private static IEnumerator SpawnPrefabsCoroutine(PrefabData[] prefabs)
@@ -164,7 +134,7 @@ private static IEnumerator SpawnPrefabsCoroutine(PrefabData[] prefabs)
164134
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
165135
for (int i = 0; i < prefabs.Length; i++)
166136
{
167-
if (sw.Elapsed.TotalSeconds > 0.1f)
137+
if (sw.Elapsed.TotalSeconds > 2f)
168138
{
169139
sw.Restart();
170140
ProgressBarManager.DisplayIncremental("Spawning Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length);
@@ -178,14 +148,6 @@ private static IEnumerator SpawnPrefabsCoroutine(PrefabData[] prefabs)
178148
ProgressBarManager.Clear();
179149
}
180150

181-
public static IEnumerator ReplaceWithLoaded(PrefabDataHolder[] prefabs)
182-
{
183-
IsBusy = true;
184-
yield return EditorCoroutineUtility.StartCoroutineOwnerless(PreparePrefabsCoroutine(prefabs));
185-
yield return EditorCoroutineUtility.StartCoroutineOwnerless(ReplaceWithLoadedCoroutine(prefabs));
186-
IsBusy = false;
187-
}
188-
189151
private static IEnumerator ReplaceWithLoadedCoroutine(PrefabDataHolder[] prefabs)
190152
{
191153
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
@@ -194,7 +156,7 @@ private static IEnumerator ReplaceWithLoadedCoroutine(PrefabDataHolder[] prefabs
194156
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
195157
for (int i = 0; i < prefabs.Length; i++)
196158
{
197-
if (sw.Elapsed.TotalSeconds > 0.1f)
159+
if (sw.Elapsed.TotalSeconds > 2f)
198160
{
199161
ProgressBarManager.DisplayIncremental("Replacing Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length);
200162
yield return null;
@@ -209,13 +171,6 @@ private static IEnumerator ReplaceWithLoadedCoroutine(PrefabDataHolder[] prefabs
209171
ProgressBarManager.Clear();
210172
}
211173

212-
public static IEnumerator ReplaceWithDefault(PrefabDataHolder[] prefabs)
213-
{
214-
IsBusy = true;
215-
yield return EditorCoroutineUtility.StartCoroutineOwnerless(ReplaceWithDefaultCoroutine(prefabs));
216-
IsBusy = false;
217-
}
218-
219174
private static IEnumerator ReplaceWithDefaultCoroutine(PrefabDataHolder[] prefabs)
220175
{
221176
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

Assets/MapEditor/WorldData/PrefabDataHolder.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55

66
[DisallowMultipleComponent]
77
[SelectionBase]
8-
[ExecuteAlways]
98
public class PrefabDataHolder : MonoBehaviour
109
{
1110
public WorldSerialization.PrefabData prefabData;
1211

13-
private void Start()
12+
public void Setup()
1413
{
1514
for (int i = 0; i < GetComponents<Component>().Length; i++)
16-
{
1715
ComponentUtility.MoveComponentUp(this);
18-
}
1916
}
17+
2018
public void UpdatePrefabData()
2119
{
2220
prefabData.position = gameObject.transform.position - (0.5f * land.terrainData.size);
2321
prefabData.rotation = transform.rotation;
2422
prefabData.scale = transform.localScale;
2523
}
24+
2625
public void SnapToGround()
2726
{
2827
Vector3 newPos = transform.position;

Assets/Resources/land.asset

0 Bytes
Binary file not shown.

Assets/Resources/water.asset

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)