78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
[CustomEditor(typeof(EnemyPortal))]
|
|
public class EnemyPortalEditor : Editor
|
|
{
|
|
private const string MONSTER_DATA_FOLDER = "Assets/Data/ScriptableObjects/Monster";
|
|
|
|
public override void OnInspectorGUI()
|
|
{
|
|
DrawDefaultInspector();
|
|
|
|
EnemyPortal portal = (EnemyPortal)target;
|
|
|
|
EditorGUILayout.Space();
|
|
EditorGUILayout.LabelField("Monster Data Loader", EditorStyles.boldLabel);
|
|
|
|
if (GUILayout.Button("Load Monster Data"))
|
|
{
|
|
LoadMonsterData(portal);
|
|
}
|
|
|
|
EditorGUILayout.HelpBox("Click 'Load Monster Data' to automatically load all monsters from " + MONSTER_DATA_FOLDER, MessageType.Info);
|
|
}
|
|
|
|
private void LoadMonsterData(EnemyPortal portal)
|
|
{
|
|
string[] guids = AssetDatabase.FindAssets("t:MonsterData", new[] { MONSTER_DATA_FOLDER });
|
|
|
|
List<EnemyPortal.MonsterEntry> entries = new List<EnemyPortal.MonsterEntry>();
|
|
int loadedCount = 0;
|
|
|
|
foreach (string guid in guids)
|
|
{
|
|
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
|
Northbound.Data.MonsterData monsterData = AssetDatabase.LoadAssetAtPath<Northbound.Data.MonsterData>(assetPath);
|
|
|
|
if (monsterData != null)
|
|
{
|
|
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(monsterData.prefabPath);
|
|
|
|
if (prefab != null)
|
|
{
|
|
entries.Add(new EnemyPortal.MonsterEntry
|
|
{
|
|
monsterData = monsterData,
|
|
prefab = prefab
|
|
});
|
|
loadedCount++;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"[EnemyPortal] Could not load prefab at path: {monsterData.prefabPath} for monster {monsterData.id}");
|
|
}
|
|
}
|
|
}
|
|
|
|
serializedObject.Update();
|
|
SerializedProperty entriesProperty = serializedObject.FindProperty("monsterEntries");
|
|
entriesProperty.ClearArray();
|
|
entriesProperty.arraySize = entries.Count;
|
|
|
|
for (int i = 0; i < entries.Count; i++)
|
|
{
|
|
SerializedProperty element = entriesProperty.GetArrayElementAtIndex(i);
|
|
element.FindPropertyRelative("monsterData").objectReferenceValue = entries[i].monsterData;
|
|
element.FindPropertyRelative("prefab").objectReferenceValue = entries[i].prefab;
|
|
}
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
AssetDatabase.SaveAssets();
|
|
|
|
Debug.Log($"[EnemyPortal] Loaded {loadedCount} monsters from {MONSTER_DATA_FOLDER}");
|
|
}
|
|
}
|