#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.IO;
using MazeGen;
namespace MazeGen.Editor
{
///
/// Provides context menu items for creating Weapon and Armor assets in the Unity Editor.
/// Assets are created in Resources folders for easy runtime loading via Resources.Load/LoadAll.
///
public class MonsterCreationMenu
{
private const string MonsterResourcePath = "Assets/Resources/Characters/Monsters/";
[MenuItem("Assets/Create/MazeGen/Characters/Monster", priority = 20)]
public static void CreateMonster()
{
CreateMonsterAsset(MonsterResourcePath, "NewMonster.asset");
}
///
/// Generic method to create and save an item asset.
/// Creates the resource folder if it doesn't exist, then shows a save dialog.
///
private static void CreateMonsterAsset(string defaultPath, string defaultName) where T : Monster
{
// Ensure the directory exists
if (!Directory.Exists(defaultPath))
{
Directory.CreateDirectory(defaultPath);
AssetDatabase.Refresh();
}
// Show save dialog
string savePath = EditorUtility.SaveFilePanelInProject(
$"Create New {typeof(T).Name}",
defaultName,
"asset",
"Choose a location and name for the new asset",
defaultPath
);
if (string.IsNullOrEmpty(savePath))
return; // User cancelled
// Create the asset
T newItem = ScriptableObject.CreateInstance();
newItem.name = Path.GetFileNameWithoutExtension(savePath);
// Save it
AssetDatabase.CreateAsset(newItem, savePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
// Select it in the Project window
EditorGUIUtility.PingObject(newItem);
Debug.Log($"Created {typeof(T).Name}: {savePath}");
}
}
}
#endif