Skip to content

Commit d44d746

Browse files
committed
Rename Prefabs
1 parent 692c3f6 commit d44d746

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

Assets/MapEditor/Editor/API/Functions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,14 +849,20 @@ public static void SelectPrefabPaths(PrefabsListTreeView treeView, ref bool show
849849
Elements.EndToolbarHorizontal();
850850
}
851851

852-
public static void HierachyOptions(PrefabDataHolder[] prefabs)
852+
853+
public static void HierachyOptions(PrefabDataHolder[] prefabs, ref string name)
853854
{
854855
Elements.MiniBoldLabel(ToolTips.hierachyOptionsLabel);
855856

857+
Elements.BeginToolbarHorizontal();
858+
name = Elements.ToolbarTextField(name);
859+
if (Elements.ToolbarButton(ToolTips.hierachyRename))
860+
PrefabManager.RenamePrefabs(prefabs, name);
861+
Elements.EndToolbarHorizontal();
862+
856863
Elements.BeginToolbarHorizontal();
857864
if (Elements.ToolbarButton(ToolTips.hierachyDelete))
858865
PrefabManager.DeletePrefabs(prefabs);
859-
860866
Elements.EndToolbarHorizontal();
861867
}
862868
#endregion

Assets/MapEditor/Editor/TreeView/PrefabHierachy/PrefabHierachyWindow.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class PrefabHierachyWindow : EditorWindow
1515
SearchField m_SearchField;
1616
PrefabHierachyTreeView m_TreeView;
1717

18+
[NonSerialized] string category;
19+
1820
Rect multiColumnTreeViewRect
1921
{
2022
get { return new Rect(20, 30, position.width - position.width / 3, position.height - 45); }
@@ -132,7 +134,7 @@ void DrawTreeView (Rect rect)
132134
void DrawOptions(Rect rect)
133135
{
134136
GUILayout.BeginArea(rect);
135-
Functions.HierachyOptions(PrefabHierachyTreeView.PrefabDataFromSelection(treeView).ToArray());
137+
Functions.HierachyOptions(PrefabHierachyTreeView.PrefabDataFromSelection(treeView).ToArray(), ref category);
136138
GUILayout.EndArea();
137139
}
138140

Assets/MapEditor/Editor/Windows/CreateMapWindow.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ public class CreateMapWindow : EditorWindow
99
Layers layers = new Layers() { Ground = TerrainSplat.Enum.Grass, Biome = TerrainBiome.Enum.Temperate };
1010
float landHeight = 505;
1111

12+
static Rect ScenePos { get => SceneView.lastActiveSceneView.position; }
13+
1214
public static void Init()
1315
{
1416
CreateMapWindow window = CreateInstance<CreateMapWindow>();
15-
window.position = new Rect(ScenePos().x + ScenePos().width / 2 - 75f, ScenePos().y + ScenePos().height / 2, 250f, 123f);
17+
window.position = new Rect(ScenePos.x + ScenePos.width / 2 - 75f, ScenePos.y + ScenePos.height / 2, 250f, 123f);
1618
window.ShowPopup();
1719
}
1820

@@ -22,9 +24,4 @@ public void OnGUI()
2224

2325
Functions.NewMapOptions(ref mapSize, ref landHeight, ref layers, this);
2426
}
25-
26-
static Rect ScenePos()
27-
{
28-
return SceneView.lastActiveSceneView.position;
29-
}
3027
}

Assets/MapEditor/Managers/PrefabManager.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ private static void OnProjectLoad()
3434
if (!AssetManager.IsInitialised && SettingsManager.LoadBundleOnProjectLoad)
3535
AssetManager.Initialise(SettingsManager.RustDirectory + SettingsManager.BundlePathExt);
3636
}
37-
3837
}
3938

4039
/// <summary>Loads, sets up and returns the prefab at the asset path.</summary>
@@ -53,6 +52,8 @@ public static GameObject Load(uint id)
5352
return Load(AssetManager.ToPath(id));
5453
}
5554

55+
56+
/// <summary>Gets the parent prefab category transform from the hierachy.</summary>
5657
public static Transform GetParent(string category)
5758
{
5859
if (PrefabCategories.TryGetValue(category, out Transform transform))
@@ -156,6 +157,12 @@ public static void ReplaceWithDefault(PrefabDataHolder[] prefabs, int progressID
156157
}
157158
}
158159

160+
public static void RenamePrefabs(PrefabDataHolder[] prefabs, string name)
161+
{
162+
foreach (var item in prefabs)
163+
item.prefabData.category = name;
164+
}
165+
159166
public static void BreakPrefab(GameObject prefab)
160167
{
161168
}

Assets/MapEditor/Scripts/ToolTips.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static class ToolTips
2626

2727
public static GUIContent hierachyOptionsLabel = new GUIContent("Hierachy Options", "Options which will affect all selected elements in the hierachy.");
2828
public static GUIContent hierachyDelete = new GUIContent("Delete", "Deletes the selected objects from the map.");
29+
public static GUIContent hierachyRename = new GUIContent("Rename", "Renames the selected objects with the input.");
2930

3031
public static GUIContent prefabHierachyName = new GUIContent("Name", "The name of the prefab.");
3132
public static GUIContent prefabHierachyType = new GUIContent("Type", "If the prefab is custom built or native to Rust.");

0 commit comments

Comments
 (0)