Touched up editor tool windows
This commit is contained in:
@@ -15,6 +15,9 @@ namespace Editor
|
|||||||
private string _pickupSoFolderPath = "Assets/Data/Items";
|
private string _pickupSoFolderPath = "Assets/Data/Items";
|
||||||
private string _puzzleSoFolderPath = "Assets/Data/Puzzles";
|
private string _puzzleSoFolderPath = "Assets/Data/Puzzles";
|
||||||
|
|
||||||
|
private enum ItemType { None, Pickup, ItemSlot }
|
||||||
|
private ItemType _itemType = ItemType.None;
|
||||||
|
|
||||||
[MenuItem("Tools/Item Prefab Editor")]
|
[MenuItem("Tools/Item Prefab Editor")]
|
||||||
public static void ShowWindow()
|
public static void ShowWindow()
|
||||||
{
|
{
|
||||||
@@ -55,28 +58,28 @@ namespace Editor
|
|||||||
|
|
||||||
EditorGUILayout.LabelField("Editing: ", _selectedGameObject.name, EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("Editing: ", _selectedGameObject.name, EditorStyles.boldLabel);
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
// Pickup
|
|
||||||
|
// Determine current type
|
||||||
bool hasPickup = _selectedGameObject.GetComponent<Pickup>() != null;
|
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 hasSlot = _selectedGameObject.GetComponent<ItemSlot>() != null;
|
||||||
bool addSlot = EditorGUILayout.Toggle("SlotItemBehavior", hasSlot);
|
if (hasSlot) _itemType = ItemType.ItemSlot;
|
||||||
if (addSlot && !hasSlot)
|
else if (hasPickup) _itemType = ItemType.Pickup;
|
||||||
{
|
else _itemType = ItemType.None;
|
||||||
PrefabEditorUtility.AddOrGetComponent<ItemSlot>(_selectedGameObject);
|
|
||||||
}
|
// Item type selection
|
||||||
else if (!addSlot && hasSlot)
|
var newType = (ItemType)EditorGUILayout.EnumPopup("Item Type", _itemType);
|
||||||
|
if (newType != _itemType)
|
||||||
{
|
{
|
||||||
|
// Remove both, then add selected
|
||||||
|
PrefabEditorUtility.RemoveComponent<Pickup>(_selectedGameObject);
|
||||||
PrefabEditorUtility.RemoveComponent<ItemSlot>(_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
|
// ObjectiveStepBehaviour
|
||||||
bool hasObjective = _selectedGameObject.GetComponent<ObjectiveStepBehaviour>() != null;
|
bool hasObjective = _selectedGameObject.GetComponent<ObjectiveStepBehaviour>() != null;
|
||||||
bool addObjective = EditorGUILayout.Toggle("ObjectiveStepBehaviour", hasObjective);
|
bool addObjective = EditorGUILayout.Toggle("ObjectiveStepBehaviour", hasObjective);
|
||||||
@@ -88,8 +91,9 @@ namespace Editor
|
|||||||
{
|
{
|
||||||
PrefabEditorUtility.RemoveComponent<ObjectiveStepBehaviour>(_selectedGameObject);
|
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>();
|
var pickup = _selectedGameObject.GetComponent<Pickup>();
|
||||||
_pickupData = pickup.itemData;
|
_pickupData = pickup.itemData;
|
||||||
@@ -113,6 +117,7 @@ namespace Editor
|
|||||||
pickup.itemData = _pickupData;
|
pickup.itemData = _pickupData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Objective Data
|
// Objective Data
|
||||||
if (addObjective)
|
if (addObjective)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,15 +12,17 @@ namespace Editor
|
|||||||
private string _saveFolderPath = "Assets/Prefabs/Items";
|
private string _saveFolderPath = "Assets/Prefabs/Items";
|
||||||
private string _pickupSoFolderPath = "Assets/Data/Items";
|
private string _pickupSoFolderPath = "Assets/Data/Items";
|
||||||
private string _puzzleSoFolderPath = "Assets/Data/Puzzles";
|
private string _puzzleSoFolderPath = "Assets/Data/Puzzles";
|
||||||
private bool _addPickup;
|
|
||||||
private bool _addCombineWith;
|
|
||||||
private bool _addSlot;
|
|
||||||
private bool _addObjective;
|
private bool _addObjective;
|
||||||
|
|
||||||
private PickupItemData _pickupData;
|
private PickupItemData _pickupData;
|
||||||
private PuzzleStepSO _objectiveData;
|
private PuzzleStepSO _objectiveData;
|
||||||
private UnityEditor.Editor _soEditor;
|
private UnityEditor.Editor _soEditor;
|
||||||
|
|
||||||
|
private enum ItemType { None, Pickup, ItemSlot }
|
||||||
|
private ItemType _itemType = ItemType.None;
|
||||||
|
|
||||||
|
private bool _createNext = false;
|
||||||
|
|
||||||
[MenuItem("Tools/Prefab Creator")]
|
[MenuItem("Tools/Prefab Creator")]
|
||||||
public static void ShowWindow()
|
public static void ShowWindow()
|
||||||
{
|
{
|
||||||
@@ -50,13 +52,19 @@ namespace Editor
|
|||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
EditorGUILayout.LabelField("Add Components:", EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("Add Components:", EditorStyles.boldLabel);
|
||||||
_addPickup = EditorGUILayout.Toggle("Pickup", _addPickup);
|
|
||||||
_addCombineWith = EditorGUILayout.Toggle("CombineWithBehavior", _addCombineWith);
|
// Item type selection
|
||||||
_addSlot = EditorGUILayout.Toggle("SlotItemBehavior", _addSlot);
|
var newType = (ItemType)EditorGUILayout.EnumPopup("Item Type", _itemType);
|
||||||
_addObjective = EditorGUILayout.Toggle("ObjectiveStepBehaviour", _addObjective);
|
if (newType != _itemType)
|
||||||
|
{
|
||||||
|
_itemType = newType;
|
||||||
|
}
|
||||||
|
bool addObjective = EditorGUILayout.Toggle("ObjectiveStepBehaviour", _addObjective);
|
||||||
|
_addObjective = addObjective;
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
if (_addPickup)
|
// Pickup Data (for Pickup or ItemSlot)
|
||||||
|
if (_itemType == ItemType.Pickup || _itemType == ItemType.ItemSlot)
|
||||||
{
|
{
|
||||||
EditorGUILayout.LabelField("Pickup Data:", EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("Pickup Data:", EditorStyles.boldLabel);
|
||||||
_pickupData = (PickupItemData)EditorGUILayout.ObjectField("PickupItemData", _pickupData, typeof(PickupItemData), false);
|
_pickupData = (PickupItemData)EditorGUILayout.ObjectField("PickupItemData", _pickupData, typeof(PickupItemData), false);
|
||||||
@@ -78,6 +86,7 @@ namespace Editor
|
|||||||
PrefabEditorUtility.DrawScriptableObjectEditor(ref _soEditor, _pickupData);
|
PrefabEditorUtility.DrawScriptableObjectEditor(ref _soEditor, _pickupData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Objective Data
|
||||||
if (_addObjective)
|
if (_addObjective)
|
||||||
{
|
{
|
||||||
EditorGUILayout.LabelField("Objective Data:", EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("Objective Data:", EditorStyles.boldLabel);
|
||||||
@@ -101,12 +110,15 @@ namespace Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
GUILayout.FlexibleSpace();
|
GUILayout.FlexibleSpace();
|
||||||
|
EditorGUILayout.BeginHorizontal();
|
||||||
GUI.enabled = !string.IsNullOrEmpty(_prefabName) && !string.IsNullOrEmpty(_saveFolderPath);
|
GUI.enabled = !string.IsNullOrEmpty(_prefabName) && !string.IsNullOrEmpty(_saveFolderPath);
|
||||||
if (GUILayout.Button("Create Prefab"))
|
if (GUILayout.Button("Create Prefab", GUILayout.Height(28)))
|
||||||
{
|
{
|
||||||
CreatePrefab();
|
CreatePrefab();
|
||||||
}
|
}
|
||||||
|
_createNext = GUILayout.Toggle(_createNext, "Create Next", GUILayout.Width(100), GUILayout.Height(28));
|
||||||
GUI.enabled = true;
|
GUI.enabled = true;
|
||||||
|
EditorGUILayout.EndHorizontal();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreatePrefab()
|
private void CreatePrefab()
|
||||||
@@ -118,14 +130,15 @@ namespace Editor
|
|||||||
if (interactableLayer != -1)
|
if (interactableLayer != -1)
|
||||||
go.layer = interactableLayer;
|
go.layer = interactableLayer;
|
||||||
go.AddComponent<SpriteRenderer>();
|
go.AddComponent<SpriteRenderer>();
|
||||||
if (_addPickup)
|
if (_itemType == ItemType.Pickup)
|
||||||
{
|
{
|
||||||
var pickup = go.AddComponent<Pickup>();
|
var pickup = go.AddComponent<Pickup>();
|
||||||
pickup.itemData = _pickupData;
|
pickup.itemData = _pickupData;
|
||||||
}
|
}
|
||||||
if (_addSlot)
|
else if (_itemType == ItemType.ItemSlot)
|
||||||
{
|
{
|
||||||
go.AddComponent<ItemSlot>();
|
var slot = go.AddComponent<ItemSlot>();
|
||||||
|
slot.itemData = _pickupData;
|
||||||
}
|
}
|
||||||
if (_addObjective)
|
if (_addObjective)
|
||||||
{
|
{
|
||||||
@@ -133,10 +146,23 @@ namespace Editor
|
|||||||
obj.stepData = _objectiveData;
|
obj.stepData = _objectiveData;
|
||||||
}
|
}
|
||||||
string prefabPath = Path.Combine(_saveFolderPath, _prefabName + ".prefab").Replace("\\", "/");
|
string prefabPath = Path.Combine(_saveFolderPath, _prefabName + ".prefab").Replace("\\", "/");
|
||||||
PrefabUtility.SaveAsPrefabAsset(go, prefabPath);
|
var prefab = PrefabUtility.SaveAsPrefabAsset(go, prefabPath);
|
||||||
DestroyImmediate(go);
|
DestroyImmediate(go);
|
||||||
AssetDatabase.Refresh();
|
AssetDatabase.Refresh();
|
||||||
|
Selection.activeObject = prefab;
|
||||||
|
EditorGUIUtility.PingObject(prefab);
|
||||||
EditorUtility.DisplayDialog("Prefab Created", $"Prefab saved to {prefabPath}", "OK");
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -577,7 +577,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6254953093500072797, guid: b5fc01af35233eb4cbeede05e50a7c34, type: 3}
|
- target: {fileID: 6254953093500072797, guid: b5fc01af35233eb4cbeede05e50a7c34, type: 3}
|
||||||
propertyPath: isOneTime
|
propertyPath: isOneTime
|
||||||
value: 1
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 6254953093500072797, guid: b5fc01af35233eb4cbeede05e50a7c34, type: 3}
|
- target: {fileID: 6254953093500072797, guid: b5fc01af35233eb4cbeede05e50a7c34, type: 3}
|
||||||
propertyPath: characterToInteract
|
propertyPath: characterToInteract
|
||||||
|
|||||||
Reference in New Issue
Block a user