Skip to content

Commit 7074ac5

Browse files
committed
Removed PrepareCoroutines
- Removed PrepareCoroutines as they were only being used as a workaround to a now fixed Unity bug. - LoadedPrefab spawn coroutines changed from every 100ms to every 1000ms. (Increases spawn times by around 5%)
1 parent 98ae3dc commit 7074ac5

File tree

1 file changed

+10
-56
lines changed

1 file changed

+10
-56
lines changed

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -107,53 +107,22 @@ private static class Coroutines
107107
public static IEnumerator SpawnPrefabs(PrefabData[] prefabs)
108108
{
109109
IsBusy = true;
110-
yield return EditorCoroutineUtility.StartCoroutineOwnerless(PreparePrefabsCoroutine(prefabs));
111110
yield return EditorCoroutineUtility.StartCoroutineOwnerless(SpawnPrefabsCoroutine(prefabs));
112111
IsBusy = false;
113112
}
114113

115-
private static IEnumerator PreparePrefabsCoroutine(PrefabData[] prefabs)
114+
public static IEnumerator ReplaceWithLoaded(PrefabDataHolder[] prefabs)
116115
{
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();
116+
IsBusy = true;
117+
yield return EditorCoroutineUtility.StartCoroutineOwnerless(ReplaceWithLoadedCoroutine(prefabs));
118+
IsBusy = false;
135119
}
136120

137-
private static IEnumerator PreparePrefabsCoroutine(PrefabDataHolder[] prefabs)
121+
public static IEnumerator ReplaceWithDefault(PrefabDataHolder[] prefabs)
138122
{
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();
123+
IsBusy = true;
124+
yield return EditorCoroutineUtility.StartCoroutineOwnerless(ReplaceWithDefaultCoroutine(prefabs));
125+
IsBusy = false;
157126
}
158127

159128
private static IEnumerator SpawnPrefabsCoroutine(PrefabData[] prefabs)
@@ -164,7 +133,7 @@ private static IEnumerator SpawnPrefabsCoroutine(PrefabData[] prefabs)
164133
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
165134
for (int i = 0; i < prefabs.Length; i++)
166135
{
167-
if (sw.Elapsed.TotalSeconds > 0.1f)
136+
if (sw.Elapsed.TotalSeconds > 1f)
168137
{
169138
sw.Restart();
170139
ProgressBarManager.DisplayIncremental("Spawning Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length);
@@ -178,14 +147,6 @@ private static IEnumerator SpawnPrefabsCoroutine(PrefabData[] prefabs)
178147
ProgressBarManager.Clear();
179148
}
180149

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-
189150
private static IEnumerator ReplaceWithLoadedCoroutine(PrefabDataHolder[] prefabs)
190151
{
191152
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
@@ -194,7 +155,7 @@ private static IEnumerator ReplaceWithLoadedCoroutine(PrefabDataHolder[] prefabs
194155
ProgressBarManager.SetProgressIncrement(1f / prefabs.Length);
195156
for (int i = 0; i < prefabs.Length; i++)
196157
{
197-
if (sw.Elapsed.TotalSeconds > 0.1f)
158+
if (sw.Elapsed.TotalSeconds > 1f)
198159
{
199160
ProgressBarManager.DisplayIncremental("Replacing Prefabs", "Spawning Prefabs: " + i + " / " + prefabs.Length);
200161
yield return null;
@@ -209,13 +170,6 @@ private static IEnumerator ReplaceWithLoadedCoroutine(PrefabDataHolder[] prefabs
209170
ProgressBarManager.Clear();
210171
}
211172

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

0 commit comments

Comments
 (0)