Files
Northbound/Assets/Scripts/Editor/MonsterPrefabSetup.cs
dal4segno 2593b6dd37 데이터 파이프라인 개선 및 포탈 로직 생성
csv import 시 자동으로 완전한 프리팹이 생성될 수 있도록 함.
2026-02-01 00:29:22 +09:00

100 lines
3.8 KiB
C#

using Northbound.Data;
using UnityEditor;
using UnityEngine;
namespace Northbound.Editor
{
public class MonsterPrefabSetup : IPrefabSetup
{
public string GetTemplateName()
{
return "MonsterTemplate";
}
public void SetupPrefab(GameObject prefab, ScriptableObject data)
{
if (!(data is MonsterData monsterData))
{
Debug.LogWarning($"[MonsterPrefabSetup] Expected MonsterData, got {data.GetType().Name}");
return;
}
var monsterDataComponent = prefab.GetComponent<MonsterDataComponent>();
if (monsterDataComponent != null)
{
monsterDataComponent.monsterData = monsterData;
monsterDataComponent.ApplyMonsterData();
}
if (!string.IsNullOrEmpty(monsterData.meshPath))
{
RemoveOldModel(prefab);
if (monsterData.meshPath.ToLower().EndsWith(".fbx"))
{
GameObject fbxModel = AssetDatabase.LoadAssetAtPath<GameObject>(monsterData.meshPath);
if (fbxModel != null)
{
GameObject fbxInstance = GameObject.Instantiate(fbxModel);
fbxInstance.name = "Model";
fbxInstance.transform.SetParent(prefab.transform, false);
fbxInstance.transform.localPosition = Vector3.zero;
fbxInstance.transform.localRotation = Quaternion.identity;
fbxInstance.transform.localScale = Vector3.one;
Debug.Log($"[MonsterPrefabSetup] Applied FBX model: {monsterData.meshPath}");
}
else
{
Debug.LogWarning($"[MonsterPrefabSetup] Could not load FBX model: {monsterData.meshPath}");
}
}
else
{
var meshFilter = prefab.GetComponent<MeshFilter>();
if (meshFilter != null)
{
Mesh mesh = AssetDatabase.LoadAssetAtPath<Mesh>(monsterData.meshPath);
if (mesh != null)
{
meshFilter.sharedMesh = mesh;
Debug.Log($"[MonsterPrefabSetup] Applied mesh: {monsterData.meshPath}");
}
else
{
Debug.LogWarning($"[MonsterPrefabSetup] Could not load mesh: {monsterData.meshPath}");
}
}
}
}
if (!string.IsNullOrEmpty(monsterData.animatorControllerPath))
{
Animator animator = prefab.GetComponent<Animator>();
if (animator != null)
{
RuntimeAnimatorController controller = AssetDatabase.LoadAssetAtPath<RuntimeAnimatorController>(monsterData.animatorControllerPath);
if (controller != null)
{
animator.runtimeAnimatorController = controller;
Debug.Log($"[MonsterPrefabSetup] Applied Animator Controller: {monsterData.animatorControllerPath}");
}
else
{
Debug.LogWarning($"[MonsterPrefabSetup] Could not load Animator Controller: {monsterData.animatorControllerPath}");
}
}
}
}
private void RemoveOldModel(GameObject prefab)
{
Transform oldModel = prefab.transform.Find("Model");
if (oldModel != null)
{
GameObject.DestroyImmediate(oldModel.gameObject);
}
}
}
}