Touched up editor tool windows

This commit is contained in:
Michal Pikulski
2025-09-11 13:15:43 +02:00
parent e1ff13db30
commit 6c76759057
3 changed files with 64 additions and 33 deletions

View File

@@ -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<Pickup>() != null;
bool addPickup = EditorGUILayout.Toggle("Pickup", hasPickup);
if (addPickup && !hasPickup)
{
PrefabEditorUtility.AddOrGetComponent<Pickup>(_selectedGameObject);
}
else if (!addPickup && hasPickup)
{
PrefabEditorUtility.RemoveComponent<Pickup>(_selectedGameObject);
}
// SlotItemBehavior
bool hasSlot = _selectedGameObject.GetComponent<ItemSlot>() != null;
bool addSlot = EditorGUILayout.Toggle("SlotItemBehavior", hasSlot);
if (addSlot && !hasSlot)
{
PrefabEditorUtility.AddOrGetComponent<ItemSlot>(_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<Pickup>(_selectedGameObject);
PrefabEditorUtility.RemoveComponent<ItemSlot>(_selectedGameObject);
if (newType == ItemType.Pickup)
PrefabEditorUtility.AddOrGetComponent<Pickup>(_selectedGameObject);
else if (newType == ItemType.ItemSlot)
PrefabEditorUtility.AddOrGetComponent<ItemSlot>(_selectedGameObject);
_itemType = newType;
}
// ObjectiveStepBehaviour
bool hasObjective = _selectedGameObject.GetComponent<ObjectiveStepBehaviour>() != null;
bool addObjective = EditorGUILayout.Toggle("ObjectiveStepBehaviour", hasObjective);
@@ -88,8 +91,9 @@ namespace Editor
{
PrefabEditorUtility.RemoveComponent<ObjectiveStepBehaviour>(_selectedGameObject);
}
// Pickup Data
if (addPickup)
// Pickup Data (for Pickup or ItemSlot)
if (_itemType == ItemType.Pickup || _itemType == ItemType.ItemSlot)
{
var pickup = _selectedGameObject.GetComponent<Pickup>();
_pickupData = pickup.itemData;
@@ -113,6 +117,7 @@ namespace Editor
pickup.itemData = _pickupData;
}
}
// Objective Data
if (addObjective)
{

View File

@@ -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<SpriteRenderer>();
if (_addPickup)
if (_itemType == ItemType.Pickup)
{
var pickup = go.AddComponent<Pickup>();
pickup.itemData = _pickupData;
}
if (_addSlot)
else if (_itemType == ItemType.ItemSlot)
{
go.AddComponent<ItemSlot>();
var slot = go.AddComponent<ItemSlot>();
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();
}
}
}
}

View File

@@ -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