데이터 파이프라인 플레이어 부분 개선
This commit is contained in:
@@ -59,7 +59,8 @@ namespace Northbound.Editor
|
||||
prefabSetups = new Dictionary<string, IPrefabSetup>
|
||||
{
|
||||
{ "Monster", new MonsterPrefabSetup() },
|
||||
{ "Tower", new TowerPrefabSetup() }
|
||||
{ "Tower", new TowerPrefabSetup() },
|
||||
{ "Player", new PlayerPrefabSetup() }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -112,7 +113,14 @@ namespace Northbound.Editor
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"[CSVToSOImporter] {typeName}: {successCount} prefabs created/updated");
|
||||
if (typeName == "Player")
|
||||
{
|
||||
Debug.Log($"[CSVToSOImporter] {typeName}: Player prefab updated successfully");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"[CSVToSOImporter] {typeName}: {successCount} prefabs created/updated");
|
||||
}
|
||||
|
||||
// If towers were imported, auto-configure BuildingManager
|
||||
// TowerData now extends BuildingData, so it can be used directly!
|
||||
@@ -174,16 +182,25 @@ namespace Northbound.Editor
|
||||
}
|
||||
}
|
||||
|
||||
string prefabPath = $"Assets/Prefabs/{typeName}/{typeName}{id}.prefab";
|
||||
Directory.CreateDirectory(Path.Combine(Application.dataPath, $"Prefabs/{typeName}"));
|
||||
GameObject prefabObj;
|
||||
if (typeName == "Player")
|
||||
{
|
||||
PlayerPrefabSetup.UpdatePlayerPrefab((PlayerData)data);
|
||||
prefabObj = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
string prefabPath = $"Assets/Prefabs/{typeName}/{typeName}{id}.prefab";
|
||||
Directory.CreateDirectory(Path.Combine(Application.dataPath, $"Prefabs/{typeName}"));
|
||||
|
||||
GameObject prefabInstance = GameObject.Instantiate(template);
|
||||
prefabInstance.name = $"{typeName}{id}";
|
||||
GameObject prefabInstance = GameObject.Instantiate(template);
|
||||
prefabInstance.name = $"{typeName}{id}";
|
||||
|
||||
prefabSetup.SetupPrefab(prefabInstance, data);
|
||||
prefabSetup.SetupPrefab(prefabInstance, data);
|
||||
|
||||
GameObject prefabObj = PrefabUtility.SaveAsPrefabAsset(prefabInstance, prefabPath);
|
||||
GameObject.DestroyImmediate(prefabInstance);
|
||||
prefabObj = PrefabUtility.SaveAsPrefabAsset(prefabInstance, prefabPath);
|
||||
GameObject.DestroyImmediate(prefabInstance);
|
||||
}
|
||||
|
||||
// Now set the prefab reference on data
|
||||
if (data is BuildingData buildingData)
|
||||
|
||||
92
Assets/Scripts/Editor/PlayerPrefabSetup.cs
Normal file
92
Assets/Scripts/Editor/PlayerPrefabSetup.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using Northbound.Data;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Northbound.Editor
|
||||
{
|
||||
public class PlayerPrefabSetup : IPrefabSetup
|
||||
{
|
||||
public string GetTemplateName()
|
||||
{
|
||||
return "Player";
|
||||
}
|
||||
|
||||
public static void UpdatePlayerPrefab(PlayerData playerData)
|
||||
{
|
||||
string prefabPath = playerData.prefabPath;
|
||||
if (!prefabPath.EndsWith(".prefab"))
|
||||
{
|
||||
prefabPath += ".prefab";
|
||||
}
|
||||
|
||||
GameObject prefabObj = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
||||
if (prefabObj == null)
|
||||
{
|
||||
Debug.LogError($"[PlayerPrefabSetup] Player prefab not found at: {prefabPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
SetupPrefabComponents(prefabObj, playerData);
|
||||
EditorUtility.SetDirty(prefabObj);
|
||||
PrefabUtility.SavePrefabAsset(prefabObj);
|
||||
Debug.Log($"[PlayerPrefabSetup] Player prefab updated from: {prefabPath}");
|
||||
}
|
||||
|
||||
public void SetupPrefab(GameObject prefab, ScriptableObject data)
|
||||
{
|
||||
if (!(data is PlayerData playerData))
|
||||
{
|
||||
Debug.LogWarning($"[PlayerPrefabSetup] Expected PlayerData, got {data.GetType().Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
SetupPrefabComponents(prefab, playerData);
|
||||
}
|
||||
|
||||
private static void SetupPrefabComponents(GameObject prefab, PlayerData playerData)
|
||||
{
|
||||
var networkController = prefab.GetComponent<NetworkPlayerController>();
|
||||
if (networkController != null)
|
||||
{
|
||||
SerializedObject so = new SerializedObject(networkController);
|
||||
so.FindProperty("moveSpeed").floatValue = playerData.moveSpeed;
|
||||
so.FindProperty("maxHealth").intValue = playerData.maxHp;
|
||||
so.ApplyModifiedProperties();
|
||||
Debug.Log($"[PlayerPrefabSetup] Updated NetworkPlayerController: moveSpeed={playerData.moveSpeed}, maxHealth={playerData.maxHp}");
|
||||
}
|
||||
|
||||
var attackAction = prefab.GetComponent<AttackAction>();
|
||||
if (attackAction != null)
|
||||
{
|
||||
SerializedObject so = new SerializedObject(attackAction);
|
||||
so.FindProperty("attackRange").intValue = playerData.atkRange;
|
||||
so.FindProperty("attackDamage").intValue = playerData.atkDamage;
|
||||
so.FindProperty("attackCooldown").floatValue = playerData.atkIntervalSec;
|
||||
so.ApplyModifiedProperties();
|
||||
Debug.Log($"[PlayerPrefabSetup] Updated AttackAction: attackRange={playerData.atkRange}, attackDamage={playerData.atkDamage}, attackCooldown={playerData.atkIntervalSec}");
|
||||
}
|
||||
|
||||
var visionProvider = prefab.GetComponent<PlayerVisionProvider>();
|
||||
if (visionProvider != null)
|
||||
{
|
||||
SerializedObject so = new SerializedObject(visionProvider);
|
||||
so.FindProperty("visionRange").floatValue = playerData.visionRadius;
|
||||
so.ApplyModifiedProperties();
|
||||
Debug.Log($"[PlayerPrefabSetup] Updated PlayerVisionProvider: visionRange={playerData.visionRadius}");
|
||||
}
|
||||
|
||||
var resourceInventory = prefab.GetComponent<PlayerResourceInventory>();
|
||||
if (resourceInventory != null)
|
||||
{
|
||||
SerializedObject so = new SerializedObject(resourceInventory);
|
||||
so.FindProperty("maxResourceCapacity").intValue = playerData.capacity;
|
||||
so.ApplyModifiedProperties();
|
||||
Debug.Log($"[PlayerPrefabSetup] Updated PlayerResourceInventory: maxResourceCapacity={playerData.capacity}");
|
||||
}
|
||||
|
||||
EditorUtility.SetDirty(prefab);
|
||||
PrefabUtility.SavePrefabAsset(prefab);
|
||||
Debug.Log($"[PlayerPrefabSetup] Player prefab updated successfully from {playerData.name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Editor/PlayerPrefabSetup.cs.meta
Normal file
2
Assets/Scripts/Editor/PlayerPrefabSetup.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5d9fa32f3480914abc8b2320d315554
|
||||
Reference in New Issue
Block a user