건설 인터랙션 시 움직이지 못하는 문제 수정 2개로 분리되어 있던 타워 데이터를 하나로 통합 - 대신 타워가 아닌 건물도 공격력 등을 정의할 수 있음
102 lines
4.3 KiB
C#
102 lines
4.3 KiB
C#
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}");
|
|
}
|
|
|
|
var playerInteraction = prefab.GetComponent<PlayerInteraction>();
|
|
if (playerInteraction != null)
|
|
{
|
|
SerializedObject so = new SerializedObject(playerInteraction);
|
|
so.FindProperty("workPower").floatValue = playerData.manpower;
|
|
so.ApplyModifiedProperties();
|
|
Debug.Log($"[PlayerPrefabSetup] Updated PlayerInteraction: workPower={playerData.manpower}");
|
|
}
|
|
|
|
EditorUtility.SetDirty(prefab);
|
|
PrefabUtility.SavePrefabAsset(prefab);
|
|
Debug.Log($"[PlayerPrefabSetup] Player prefab updated successfully from {playerData.name}");
|
|
}
|
|
}
|
|
}
|