using Northbound.Data; using UnityEditor; using UnityEngine; namespace Northbound.Editor { public class CreepPrefabSetup : IPrefabSetup { public string GetTemplateName() { return "CreepTemplate"; } public void SetupPrefab(GameObject prefab, ScriptableObject data) { if (!(data is CreepData creepData)) { Debug.LogWarning($"[CreepPrefabSetup] Expected CreepData, got {data.GetType().Name}"); return; } var creepDataComponent = prefab.GetComponent(); if (creepDataComponent != null) { creepDataComponent.creepData = creepData; creepDataComponent.ApplyCreepData(); } var animationController = prefab.GetComponent(); if (animationController == null) { animationController = prefab.AddComponent(); Debug.Log($"[CreepPrefabSetup] Added MonsterAnimationController component"); } if (!string.IsNullOrEmpty(creepData.modelPath)) { RemoveOldModel(prefab); if (creepData.modelPath.ToLower().EndsWith(".fbx")) { GameObject fbxModel = AssetDatabase.LoadAssetAtPath(creepData.modelPath); 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($"[CreepPrefabSetup] Applied FBX model: {creepData.modelPath}"); Avatar modelAvatar = fbxModel.GetComponent()?.avatar; if (modelAvatar != null) { Animator prefabAnimator = prefab.GetComponent(); if (prefabAnimator != null) { prefabAnimator.avatar = modelAvatar; Debug.Log($"[CreepPrefabSetup] Applied Avatar: {modelAvatar.name}"); } } } else { Debug.LogWarning($"[CreepPrefabSetup] Could not load FBX model: {creepData.modelPath}"); } } else { var meshFilter = prefab.GetComponent(); if (meshFilter != null) { Mesh mesh = AssetDatabase.LoadAssetAtPath(creepData.modelPath); if (mesh != null) { meshFilter.sharedMesh = mesh; Debug.Log($"[CreepPrefabSetup] Applied mesh: {creepData.modelPath}"); } else { Debug.LogWarning($"[CreepPrefabSetup] Could not load mesh: {creepData.modelPath}"); } } } } if (!string.IsNullOrEmpty(creepData.animationControllerPath)) { Animator animator = prefab.GetComponent(); if (animator != null) { RuntimeAnimatorController controller = AssetDatabase.LoadAssetAtPath(creepData.animationControllerPath); if (controller != null) { animator.runtimeAnimatorController = controller; Debug.Log($"[CreepPrefabSetup] Applied Animator Controller: {creepData.animationControllerPath}"); } else { Debug.LogWarning($"[CreepPrefabSetup] Could not load Animator Controller: {creepData.animationControllerPath}"); } } } } private void RemoveOldModel(GameObject prefab) { Transform oldModel = prefab.transform.Find("Model"); if (oldModel != null) { GameObject.DestroyImmediate(oldModel.gameObject); } } } }