From 6c7675905793b701ffc3a6714df261b1908194be Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Thu, 11 Sep 2025 13:15:43 +0200 Subject: [PATCH] Touched up editor tool windows --- Assets/Editor/ItemPrefabEditor.cs | 43 ++++++++------- Assets/Editor/PrefabCreatorWindow.cs | 52 ++++++++++++++----- .../Scenes/Levels/AppleHillsOverworld.unity | 2 +- 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/Assets/Editor/ItemPrefabEditor.cs b/Assets/Editor/ItemPrefabEditor.cs index f4926896..9ea59a25 100644 --- a/Assets/Editor/ItemPrefabEditor.cs +++ b/Assets/Editor/ItemPrefabEditor.cs @@ -15,6 +15,9 @@ namespace Editor private string _pickupSoFolderPath = "Assets/Data/Items"; private string _puzzleSoFolderPath = "Assets/Data/Puzzles"; + private enum ItemType { None, Pickup, ItemSlot } + private ItemType _itemType = ItemType.None; + [MenuItem("Tools/Item Prefab Editor")] public static void ShowWindow() { @@ -55,28 +58,28 @@ namespace Editor EditorGUILayout.LabelField("Editing: ", _selectedGameObject.name, EditorStyles.boldLabel); EditorGUILayout.Space(); - // Pickup + + // Determine current type bool hasPickup = _selectedGameObject.GetComponent() != null; - bool addPickup = EditorGUILayout.Toggle("Pickup", hasPickup); - if (addPickup && !hasPickup) - { - PrefabEditorUtility.AddOrGetComponent(_selectedGameObject); - } - else if (!addPickup && hasPickup) - { - PrefabEditorUtility.RemoveComponent(_selectedGameObject); - } - // SlotItemBehavior bool hasSlot = _selectedGameObject.GetComponent() != null; - bool addSlot = EditorGUILayout.Toggle("SlotItemBehavior", hasSlot); - if (addSlot && !hasSlot) - { - PrefabEditorUtility.AddOrGetComponent(_selectedGameObject); - } - else if (!addSlot && hasSlot) + if (hasSlot) _itemType = ItemType.ItemSlot; + else if (hasPickup) _itemType = ItemType.Pickup; + else _itemType = ItemType.None; + + // Item type selection + var newType = (ItemType)EditorGUILayout.EnumPopup("Item Type", _itemType); + if (newType != _itemType) { + // Remove both, then add selected + PrefabEditorUtility.RemoveComponent(_selectedGameObject); PrefabEditorUtility.RemoveComponent(_selectedGameObject); + if (newType == ItemType.Pickup) + PrefabEditorUtility.AddOrGetComponent(_selectedGameObject); + else if (newType == ItemType.ItemSlot) + PrefabEditorUtility.AddOrGetComponent(_selectedGameObject); + _itemType = newType; } + // ObjectiveStepBehaviour bool hasObjective = _selectedGameObject.GetComponent() != null; bool addObjective = EditorGUILayout.Toggle("ObjectiveStepBehaviour", hasObjective); @@ -88,8 +91,9 @@ namespace Editor { PrefabEditorUtility.RemoveComponent(_selectedGameObject); } - // Pickup Data - if (addPickup) + + // Pickup Data (for Pickup or ItemSlot) + if (_itemType == ItemType.Pickup || _itemType == ItemType.ItemSlot) { var pickup = _selectedGameObject.GetComponent(); _pickupData = pickup.itemData; @@ -113,6 +117,7 @@ namespace Editor pickup.itemData = _pickupData; } } + // Objective Data if (addObjective) { diff --git a/Assets/Editor/PrefabCreatorWindow.cs b/Assets/Editor/PrefabCreatorWindow.cs index 9887d67c..5c8cf87e 100644 --- a/Assets/Editor/PrefabCreatorWindow.cs +++ b/Assets/Editor/PrefabCreatorWindow.cs @@ -12,15 +12,17 @@ namespace Editor private string _saveFolderPath = "Assets/Prefabs/Items"; private string _pickupSoFolderPath = "Assets/Data/Items"; private string _puzzleSoFolderPath = "Assets/Data/Puzzles"; - private bool _addPickup; - private bool _addCombineWith; - private bool _addSlot; private bool _addObjective; private PickupItemData _pickupData; private PuzzleStepSO _objectiveData; private UnityEditor.Editor _soEditor; + private enum ItemType { None, Pickup, ItemSlot } + private ItemType _itemType = ItemType.None; + + private bool _createNext = false; + [MenuItem("Tools/Prefab Creator")] public static void ShowWindow() { @@ -50,13 +52,19 @@ namespace Editor EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Add Components:", EditorStyles.boldLabel); - _addPickup = EditorGUILayout.Toggle("Pickup", _addPickup); - _addCombineWith = EditorGUILayout.Toggle("CombineWithBehavior", _addCombineWith); - _addSlot = EditorGUILayout.Toggle("SlotItemBehavior", _addSlot); - _addObjective = EditorGUILayout.Toggle("ObjectiveStepBehaviour", _addObjective); + + // Item type selection + var newType = (ItemType)EditorGUILayout.EnumPopup("Item Type", _itemType); + if (newType != _itemType) + { + _itemType = newType; + } + bool addObjective = EditorGUILayout.Toggle("ObjectiveStepBehaviour", _addObjective); + _addObjective = addObjective; EditorGUILayout.Space(); - if (_addPickup) + // Pickup Data (for Pickup or ItemSlot) + if (_itemType == ItemType.Pickup || _itemType == ItemType.ItemSlot) { EditorGUILayout.LabelField("Pickup Data:", EditorStyles.boldLabel); _pickupData = (PickupItemData)EditorGUILayout.ObjectField("PickupItemData", _pickupData, typeof(PickupItemData), false); @@ -78,6 +86,7 @@ namespace Editor PrefabEditorUtility.DrawScriptableObjectEditor(ref _soEditor, _pickupData); } } + // Objective Data if (_addObjective) { EditorGUILayout.LabelField("Objective Data:", EditorStyles.boldLabel); @@ -101,12 +110,15 @@ namespace Editor } } GUILayout.FlexibleSpace(); + EditorGUILayout.BeginHorizontal(); GUI.enabled = !string.IsNullOrEmpty(_prefabName) && !string.IsNullOrEmpty(_saveFolderPath); - if (GUILayout.Button("Create Prefab")) + if (GUILayout.Button("Create Prefab", GUILayout.Height(28))) { CreatePrefab(); } + _createNext = GUILayout.Toggle(_createNext, "Create Next", GUILayout.Width(100), GUILayout.Height(28)); GUI.enabled = true; + EditorGUILayout.EndHorizontal(); } private void CreatePrefab() @@ -118,14 +130,15 @@ namespace Editor if (interactableLayer != -1) go.layer = interactableLayer; go.AddComponent(); - if (_addPickup) + if (_itemType == ItemType.Pickup) { var pickup = go.AddComponent(); pickup.itemData = _pickupData; } - if (_addSlot) + else if (_itemType == ItemType.ItemSlot) { - go.AddComponent(); + var slot = go.AddComponent(); + slot.itemData = _pickupData; } if (_addObjective) { @@ -133,10 +146,23 @@ namespace Editor obj.stepData = _objectiveData; } string prefabPath = Path.Combine(_saveFolderPath, _prefabName + ".prefab").Replace("\\", "/"); - PrefabUtility.SaveAsPrefabAsset(go, prefabPath); + var prefab = PrefabUtility.SaveAsPrefabAsset(go, prefabPath); DestroyImmediate(go); AssetDatabase.Refresh(); + Selection.activeObject = prefab; + EditorGUIUtility.PingObject(prefab); EditorUtility.DisplayDialog("Prefab Created", $"Prefab saved to {prefabPath}", "OK"); + if (_createNext) + { + _prefabName = "NewPrefab"; + _pickupData = null; + _objectiveData = null; + _itemType = ItemType.None; + _addObjective = false; + _soEditor = null; + GUI.FocusControl(null); + Repaint(); + } } } } diff --git a/Assets/Scenes/Levels/AppleHillsOverworld.unity b/Assets/Scenes/Levels/AppleHillsOverworld.unity index f3daf791..655bfe5d 100644 --- a/Assets/Scenes/Levels/AppleHillsOverworld.unity +++ b/Assets/Scenes/Levels/AppleHillsOverworld.unity @@ -577,7 +577,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 6254953093500072797, guid: b5fc01af35233eb4cbeede05e50a7c34, type: 3} propertyPath: isOneTime - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 6254953093500072797, guid: b5fc01af35233eb4cbeede05e50a7c34, type: 3} propertyPath: characterToInteract