대장간을 이용한 업그레이드 기능 추가
This commit is contained in:
126
Assets/Scripts/Buildings/Blacksmith.cs
Normal file
126
Assets/Scripts/Buildings/Blacksmith.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using UnityEngine;
|
||||
using Unity.Netcode;
|
||||
|
||||
namespace Northbound
|
||||
{
|
||||
/// <summary>
|
||||
/// 블랙스미스 건물 - 업그레이드 구매 가능
|
||||
/// </summary>
|
||||
public class Blacksmith : MonoBehaviour, IInteractable
|
||||
{
|
||||
[Header("UI Reference")]
|
||||
[SerializeField] private GameObject _upgradePopupPrefab;
|
||||
|
||||
private GameObject _popupInstance;
|
||||
private UpgradeListPopup _upgradePopup;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 프리팹이 없으면 Resources에서 로드
|
||||
if (_upgradePopupPrefab == null)
|
||||
{
|
||||
_upgradePopupPrefab = Resources.Load<GameObject>("UI/Upgrade/UpgradeListPopup");
|
||||
}
|
||||
}
|
||||
|
||||
#region IInteractable Implementation
|
||||
|
||||
public bool CanInteract(ulong playerId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Interact(ulong playerId)
|
||||
{
|
||||
OpenUpgradePopup(playerId);
|
||||
}
|
||||
|
||||
public string GetInteractionPrompt()
|
||||
{
|
||||
return "[F] 업그레이드";
|
||||
}
|
||||
|
||||
public string GetInteractionAnimation()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
public EquipmentData GetEquipmentData()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Transform GetTransform()
|
||||
{
|
||||
return transform;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
private void OpenUpgradePopup(ulong playerId)
|
||||
{
|
||||
// 플레이어의 UpgradeManager와 Stats 찾기
|
||||
var playerObj = GetPlayerObject(playerId);
|
||||
if (playerObj == null)
|
||||
{
|
||||
Debug.LogWarning($"[Blacksmith] 플레이어 {playerId}를 찾을 수 없습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
var upgradeManager = playerObj.GetComponent<PlayerUpgradeManager>();
|
||||
var playerStats = playerObj.GetComponent<PlayerStats>();
|
||||
|
||||
if (upgradeManager == null || playerStats == null)
|
||||
{
|
||||
Debug.LogWarning("[Blacksmith] PlayerUpgradeManager 또는 PlayerStats가 없습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
// 팝업 생성
|
||||
if (_popupInstance == null && _upgradePopupPrefab != null)
|
||||
{
|
||||
_popupInstance = Instantiate(_upgradePopupPrefab);
|
||||
_upgradePopup = _popupInstance.GetComponent<UpgradeListPopup>();
|
||||
|
||||
if (_upgradePopup == null)
|
||||
{
|
||||
_upgradePopup = _popupInstance.AddComponent<UpgradeListPopup>();
|
||||
}
|
||||
}
|
||||
|
||||
// 팝업 초기화 및 열기
|
||||
if (_upgradePopup != null)
|
||||
{
|
||||
_upgradePopup.Initialize(upgradeManager, playerStats);
|
||||
}
|
||||
}
|
||||
|
||||
private GameObject GetPlayerObject(ulong playerId)
|
||||
{
|
||||
if (NetworkManager.Singleton == null) return null;
|
||||
|
||||
// NetworkManager에서 플레이어 오브젝트 찾기
|
||||
foreach (var netObj in NetworkManager.Singleton.SpawnManager.SpawnedObjects.Values)
|
||||
{
|
||||
var controller = netObj.GetComponent<NetworkPlayerController>();
|
||||
if (controller != null && controller.OwnerPlayerId == playerId)
|
||||
{
|
||||
return netObj.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_popupInstance != null)
|
||||
{
|
||||
Destroy(_popupInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Buildings/Blacksmith.cs.meta
Normal file
2
Assets/Scripts/Buildings/Blacksmith.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 39d108eb3babe48409cc4dfc803dbbe4
|
||||
Reference in New Issue
Block a user