78 lines
2.6 KiB
C#
78 lines
2.6 KiB
C#
using Northbound;
|
|
using Northbound.Data;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
[CustomEditor(typeof(EnemyPortal))]
|
|
public class EnemyPortalEditor : Editor
|
|
{
|
|
private const string MONSTER_PREFAB_FOLDER = "Assets/Prefabs/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 monster prefabs from " + MONSTER_PREFAB_FOLDER, MessageType.Info);
|
|
}
|
|
|
|
private void LoadMonsterData(EnemyPortal portal)
|
|
{
|
|
string[] guids = AssetDatabase.FindAssets("t:Prefab", new[] { MONSTER_PREFAB_FOLDER });
|
|
|
|
List<EnemyPortal.MonsterEntry> entries = new List<EnemyPortal.MonsterEntry>();
|
|
int loadedCount = 0;
|
|
|
|
foreach (string guid in guids)
|
|
{
|
|
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
|
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
|
|
|
if (prefab != null)
|
|
{
|
|
MonsterDataComponent monsterDataComponent = prefab.GetComponent<MonsterDataComponent>();
|
|
|
|
if (monsterDataComponent != null && monsterDataComponent.monsterData != null)
|
|
{
|
|
entries.Add(new EnemyPortal.MonsterEntry
|
|
{
|
|
prefab = prefab
|
|
});
|
|
loadedCount++;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"[EnemyPortal] Prefab {prefab.name} does not have MonsterDataComponent with valid monsterData reference");
|
|
}
|
|
}
|
|
}
|
|
|
|
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("prefab").objectReferenceValue = entries[i].prefab;
|
|
}
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
AssetDatabase.SaveAssets();
|
|
|
|
Debug.Log($"[EnemyPortal] Loaded {loadedCount} monsters from {MONSTER_PREFAB_FOLDER}");
|
|
}
|
|
}
|