2026-04-13 스킬,퀵슬롯 시스템 수정중
This commit is contained in:
77
Assets/02_Scripts/UI/SkillWindow/SkillEntry.cs
Normal file
77
Assets/02_Scripts/UI/SkillWindow/SkillEntry.cs
Normal file
@@ -0,0 +1,77 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SkillEntry : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
[SerializeField] private Image _iconImage;
|
||||
[SerializeField] private TextMeshProUGUI _nameText;
|
||||
|
||||
public SkillData Data { get; private set; }
|
||||
|
||||
private Transform _dragTransform;
|
||||
private Transform _originalParent;
|
||||
private CanvasGroup _canvasGroup;
|
||||
private Vector3 _originalLocalPos;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_canvasGroup = GetComponent<CanvasGroup>();
|
||||
if (_canvasGroup == null)
|
||||
_canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
public void SetData(SkillData data)
|
||||
{
|
||||
Data = data;
|
||||
if (_iconImage != null)
|
||||
{
|
||||
_iconImage.sprite = data != null ? data.Icon : null;
|
||||
_iconImage.enabled = data != null && data.Icon != null;
|
||||
}
|
||||
if (_nameText != null)
|
||||
_nameText.text = data != null ? data.EntryName : "";
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
if (Data == null)
|
||||
{
|
||||
eventData.pointerDrag = null;
|
||||
return;
|
||||
}
|
||||
|
||||
_dragTransform = GameManager.Instance.InGameUI.DragCanvas;
|
||||
_originalParent = transform.parent;
|
||||
_originalLocalPos = transform.localPosition;
|
||||
|
||||
transform.SetParent(_dragTransform);
|
||||
_canvasGroup.blocksRaycasts = false;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
transform.position = eventData.position;
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
_canvasGroup.blocksRaycasts = true;
|
||||
|
||||
// 드롭된 오브젝트 판정 — 퀵슬롯이면 등록
|
||||
GameObject hovered = eventData.pointerEnter;
|
||||
if (hovered != null)
|
||||
{
|
||||
QuickSlot slot = hovered.GetComponentInParent<QuickSlot>();
|
||||
if (slot != null && Data != null)
|
||||
{
|
||||
slot.SetEntry(Data);
|
||||
}
|
||||
}
|
||||
|
||||
// 엔트리는 항상 제자리로 복귀 (원본은 목록에 남아있어야 함)
|
||||
transform.SetParent(_originalParent);
|
||||
transform.localPosition = _originalLocalPos;
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/UI/SkillWindow/SkillEntry.cs.meta
Normal file
2
Assets/02_Scripts/UI/SkillWindow/SkillEntry.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58eac31de8e96ed4c9a5fa7206bd63f3
|
||||
43
Assets/02_Scripts/UI/SkillWindow/SkillWindowUI.cs
Normal file
43
Assets/02_Scripts/UI/SkillWindow/SkillWindowUI.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SkillWindowUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform _listContentRoot;
|
||||
[SerializeField] private GameObject _skillEntryPrefab;
|
||||
|
||||
private readonly List<SkillEntry> _entries = new List<SkillEntry>();
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
bool willOpen = !gameObject.activeSelf;
|
||||
gameObject.SetActive(willOpen);
|
||||
if (willOpen) Refresh();
|
||||
}
|
||||
|
||||
public void Refresh()
|
||||
{
|
||||
// 기존 엔트리 정리
|
||||
foreach (Transform child in _listContentRoot)
|
||||
Destroy(child.gameObject);
|
||||
_entries.Clear();
|
||||
|
||||
var character = GameManager.Instance.Level.CurrentCharacter;
|
||||
if (character == null) return;
|
||||
if (!character.TryGetComponent<SkillModule>(out var skillModule)) return;
|
||||
|
||||
var skills = skillModule.GetEquippedSkillDatas();
|
||||
for (int i = 0; i < skills.Count; i++)
|
||||
{
|
||||
if (skills[i] == null) continue;
|
||||
|
||||
GameObject entryObj = Instantiate(_skillEntryPrefab, _listContentRoot);
|
||||
SkillEntry entry = entryObj.GetComponent<SkillEntry>();
|
||||
if (entry != null)
|
||||
{
|
||||
entry.SetData(skills[i]);
|
||||
_entries.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/UI/SkillWindow/SkillWindowUI.cs.meta
Normal file
2
Assets/02_Scripts/UI/SkillWindow/SkillWindowUI.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0abbd5b063416be4c97a8429d13b4b53
|
||||
Reference in New Issue
Block a user