Skip to content

Commit 692c3f6

Browse files
committed
Parent prefabs to prefab categories
1 parent 0159978 commit 692c3f6

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
using UnityEngine;
22
using UnityEditor;
3-
using RustMapEditor.Data;
43
using static WorldSerialization;
54
using Unity.EditorCoroutines.Editor;
65
using System.Collections;
76
using System.Linq;
7+
using System.Collections.Generic;
88

99
public static class PrefabManager
1010
{
1111
public static GameObject DefaultPrefab { get; private set; }
1212
public static Transform PrefabParent { get; private set; }
1313
public static GameObject PrefabToSpawn;
14+
1415
public static PrefabDataHolder[] CurrentMapPrefabs { get => PrefabParent.gameObject.GetComponentsInChildren<PrefabDataHolder>(); }
1516

17+
public static Dictionary<string, Transform> PrefabCategories = new Dictionary<string, Transform>();
18+
1619
public static bool IsChangingPrefabs { get; private set; }
1720

1821
[InitializeOnLoadMethod]
@@ -50,6 +53,18 @@ public static GameObject Load(uint id)
5053
return Load(AssetManager.ToPath(id));
5154
}
5255

56+
public static Transform GetParent(string category)
57+
{
58+
if (PrefabCategories.TryGetValue(category, out Transform transform))
59+
return transform;
60+
61+
var obj = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/PrefabCategory"), PrefabParent, false);
62+
obj.transform.localPosition = Vector3.zero;
63+
obj.name = category;
64+
PrefabCategories.Add(category, obj.transform);
65+
return obj.transform;
66+
}
67+
5368
/// <summary>Sets up the prefabs loaded from the bundle file for use in the editor.</summary>
5469
/// <param name="go">GameObject to process, should be from one of the asset bundles.</param>
5570
/// <param name="filePath">Asset filepath of the gameobject, used to get and set the PrefabID.</param>
@@ -165,7 +180,7 @@ public static IEnumerator SpawnPrefabs(PrefabData[] prefabs, int progressID)
165180
Progress.Report(progressID, (float)i / prefabs.Length, "Spawning Prefabs: " + i + " / " + prefabs.Length);
166181
sw.Restart();
167182
}
168-
Spawn(Load(prefabs[i].id), prefabs[i], PrefabParent);
183+
Spawn(Load(prefabs[i].id), prefabs[i], GetParent(prefabs[i].category));
169184
}
170185
Progress.Report(progressID, 0.99f, "Spawned " + prefabs.Length + " prefabs.");
171186
Progress.Finish(progressID, Progress.Status.Succeeded);
@@ -206,7 +221,7 @@ public static IEnumerator ReplaceWithLoaded(PrefabDataHolder[] prefabs, int prog
206221
Progress.Report(progressID, (float)i / prefabs.Length, "Replacing Prefabs: " + i + " / " + prefabs.Length);
207222
sw.Restart();
208223
}
209-
Spawn(Load(prefabs[i].prefabData.id), prefabs[i].prefabData, PrefabParent);
224+
Spawn(Load(prefabs[i].prefabData.id), prefabs[i].prefabData, GetParent(prefabs[i].prefabData.category));
210225
GameObject.DestroyImmediate(prefabs[i].gameObject);
211226
}
212227
Progress.Report(progressID, 0.99f, "Replaced " + prefabs.Length + " prefabs.");
@@ -228,7 +243,7 @@ public static IEnumerator ReplaceWithDefault(PrefabDataHolder[] prefabs, int pro
228243
Progress.Report(progressID, (float)i / prefabs.Length, "Replacing Prefabs: " + i + " / " + prefabs.Length);
229244
sw.Restart();
230245
}
231-
Spawn(DefaultPrefab, prefabs[i].prefabData, PrefabParent);
246+
Spawn(DefaultPrefab, prefabs[i].prefabData, GetParent(prefabs[i].prefabData.category));
232247
GameObject.DestroyImmediate(prefabs[i].gameObject);
233248
}
234249
Progress.Report(progressID, 0.99f, "Replaced " + prefabs.Length + " prefabs.");

Assets/MapEditor/Scripts/ToolTips.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class ToolTips
1111
public static GUIContent systemOS = new GUIContent("OS: " + SystemInfo.operatingSystem);
1212
public static GUIContent systemRAM = new GUIContent("RAM: " + SystemInfo.systemMemorySize / 1000 + "GB");
1313
public static GUIContent unityVersion = new GUIContent("Unity Version: " + Application.unityVersion);
14-
public static GUIContent editorVersion = new GUIContent("Editor Version: v0.1.4");
14+
public static GUIContent editorVersion = new GUIContent("Editor Version: v0.1.5");
1515

1616
public static GUIContent runPreset = new GUIContent("Run Preset", "Run this preset with all it's current nodes.");
1717
public static GUIContent deletePreset = new GUIContent("Delete Preset", "Delete this preset from Unity.");

0 commit comments

Comments
 (0)