Skip to content

Commit edcdec2

Browse files
committed
Merge branch 'beta'
2 parents c5beaf3 + 392c1d0 commit edcdec2

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

Assets/MapEditor/Editor/PrefabDataHolderEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public override void OnInspectorGUI()
1414
Functions.PrefabID(script);
1515
Functions.SnapToGround(script);
1616
Functions.ToggleLights(script);
17-
//Functions.BreakPrefab(script);
17+
Functions.BreakPrefab(script);
1818
}
1919
}

Assets/MapEditor/Managers/MapManager.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -716,20 +716,20 @@ public static IEnumerator Load(MapInfo mapInfo, string loadPath = "")
716716
}
717717

718718
int progressID = Progress.Start("Load: " + loadPath.Split('/').Last(), "Preparing Map", Progress.Options.Sticky);
719-
int prefabID = Progress.Start("Prefabs", null, Progress.Options.Sticky, progressID);
720-
int prefabID2 = Progress.Start("Prefabs", null, Progress.Options.Sticky, progressID);
721-
int pathID = Progress.Start("Paths", null, Progress.Options.Sticky, progressID);
722-
int pathID2 = Progress.Start("Paths", null, Progress.Options.Sticky, progressID);
719+
int delPrefab = Progress.Start("Prefabs", null, Progress.Options.Sticky, progressID);
720+
int spwPrefab = Progress.Start("Prefabs", null, Progress.Options.Sticky, progressID);
721+
int delPath = Progress.Start("Paths", null, Progress.Options.Sticky, progressID);
722+
int spwPath = Progress.Start("Paths", null, Progress.Options.Sticky, progressID);
723723
int terrainID = Progress.Start("Terrain", null, Progress.Options.Sticky, progressID);
724724

725725
var splatMapTask = Task.Run(() => SetSplatMaps(mapInfo));
726726

727-
PrefabManager.DeletePrefabs(PrefabManager.CurrentMapPrefabs, prefabID);
728-
PathManager.DeletePaths(PathManager.CurrentMapPaths, pathID);
727+
PrefabManager.DeletePrefabs(PrefabManager.CurrentMapPrefabs, delPrefab);
728+
PathManager.DeletePaths(PathManager.CurrentMapPaths, delPath);
729729
CentreSceneObjects(mapInfo);
730730
SetTerrain(mapInfo, terrainID);
731-
PrefabManager.SpawnPrefabs(mapInfo.prefabData, prefabID2);
732-
PathManager.SpawnPaths(mapInfo.pathData, pathID2);
731+
PrefabManager.SpawnPrefabs(mapInfo.prefabData, spwPrefab);
732+
PathManager.SpawnPaths(mapInfo.pathData, spwPath);
733733

734734
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
735735
sw.Start();
@@ -741,8 +741,18 @@ public static IEnumerator Load(MapInfo mapInfo, string loadPath = "")
741741
yield return null;
742742
}
743743
}
744+
744745
SetLayer(LandLayer, TerrainTopology.TypeToIndex((int)TopologyLayer)); // Sets the alphamaps to the currently selected.
745-
yield return null;
746+
747+
while (Progress.GetProgressById(spwPrefab).running)
748+
{
749+
if (sw.Elapsed.TotalMilliseconds > 0.05f)
750+
{
751+
sw.Restart();
752+
yield return null;
753+
}
754+
}
755+
746756
Progress.Report(progressID, 0.99f, "Loaded");
747757
Progress.Finish(progressID, Progress.Status.Succeeded);
748758
}

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,44 @@ public static void RenamePrefabs(PrefabDataHolder[] prefabs, string name)
165165

166166
public static void BreakPrefab(GameObject prefab)
167167
{
168+
EditorCoroutineUtility.StartCoroutineOwnerless(Coroutines.BreakPrefab(prefab));
168169
}
169170

170171
private static class Coroutines
171172
{
173+
public static IEnumerator BreakPrefab(GameObject prefab)
174+
{
175+
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
176+
sw.Start();
177+
178+
var transforms = prefab.GetComponentsInChildren<Transform>();
179+
int progressId = Progress.Start("Break Prefab", null, Progress.Options.Sticky);
180+
181+
for (int i = 0; i < transforms.Length; i++)
182+
{
183+
if (sw.Elapsed.TotalSeconds > 0.5f)
184+
{
185+
yield return null;
186+
Progress.Report(progressId, (float)i / transforms.Length, "Scanning Prefab: " + i + " / " + transforms.Length);
187+
sw.Restart();
188+
}
189+
var nameSplit = transforms[i].gameObject.name.Split(' ');
190+
var prefabName = nameSplit[0].Trim() + ".prefab";
191+
var prefabPaths = AssetManager.ManifestStrings.Where(x => x.Contains(prefabName));
192+
if (prefabPaths.Count() == 1)
193+
{
194+
GameObject go = GameObject.Instantiate(Load(prefabPaths.First()), PrefabParent);
195+
go.transform.position = transforms[i].gameObject.transform.position;
196+
go.transform.rotation = transforms[i].gameObject.transform.rotation;
197+
go.transform.localScale = transforms[i].gameObject.transform.localScale;
198+
go.name = Load(prefabPaths.First()).name;
199+
go.SetActive(true);
200+
}
201+
}
202+
GameObject.DestroyImmediate(prefab);
203+
Progress.Finish(progressId);
204+
}
205+
172206
public static IEnumerator SpawnPrefabs(PrefabData[] prefabs, int progressID)
173207
{
174208
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
@@ -254,4 +288,4 @@ public static IEnumerator ReplaceWithDefault(PrefabDataHolder[] prefabs, int pro
254288
IsChangingPrefabs = false;
255289
}
256290
}
257-
}
291+
}

0 commit comments

Comments
 (0)