using UnityEngine;
using System.Collections.Generic;
namespace Northbound
{
///
/// 플레이어의 장비 소켓 관리 (손, 등, 허리 등)
///
public class EquipmentSocket : MonoBehaviour
{
[System.Serializable]
public class Socket
{
public string socketName; // "RightHand", "LeftHand", "Back" 등
public Transform socketTransform; // 실제 본 Transform
[HideInInspector] public GameObject currentEquipment; // 현재 장착된 장비
}
[Header("Available Sockets")]
public List sockets = new List();
private Dictionary _socketDict = new Dictionary();
private void Awake()
{
// 빠른 검색을 위한 딕셔너리 생성
foreach (var socket in sockets)
{
if (!string.IsNullOrEmpty(socket.socketName))
{
_socketDict[socket.socketName] = socket;
}
}
}
///
/// 소켓에 장비 부착
///
public GameObject AttachToSocket(string socketName, GameObject equipmentPrefab)
{
if (!_socketDict.TryGetValue(socketName, out Socket socket))
{
Debug.LogWarning($"소켓을 찾을 수 없습니다: {socketName}");
return null;
}
if (socket.socketTransform == null)
{
Debug.LogWarning($"소켓 Transform이 없습니다: {socketName}");
return null;
}
// 기존 장비 제거
DetachFromSocket(socketName);
// 새 장비 생성
if (equipmentPrefab != null)
{
GameObject equipment = Instantiate(equipmentPrefab, socket.socketTransform);
equipment.transform.localPosition = Vector3.zero;
equipment.transform.localRotation = Quaternion.identity;
socket.currentEquipment = equipment;
return equipment;
}
return null;
}
///
/// 소켓에서 장비 제거
///
public void DetachFromSocket(string socketName)
{
if (!_socketDict.TryGetValue(socketName, out Socket socket))
return;
if (socket.currentEquipment != null)
{
Destroy(socket.currentEquipment);
socket.currentEquipment = null;
}
}
///
/// 모든 소켓에서 장비 제거
///
public void DetachAll()
{
foreach (var socket in sockets)
{
if (socket.currentEquipment != null)
{
Destroy(socket.currentEquipment);
socket.currentEquipment = null;
}
}
}
///
/// 특정 소켓에 장비가 있는지 확인
///
public bool HasEquipment(string socketName)
{
if (_socketDict.TryGetValue(socketName, out Socket socket))
{
return socket.currentEquipment != null;
}
return false;
}
}
}