feat: 스킬 편집 UI 내의 스킬 슬롯, 스킬 정보 클릭 액션 적용
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
@@ -12,10 +15,36 @@ namespace TON
|
||||
public SkillSettingUI_SkillSlot skillSlotPrefab;
|
||||
public List<SkillSettingUI_SkillSlot> createSkillSlots = new List<SkillSettingUI_SkillSlot>();
|
||||
|
||||
public ScrollRect scrollRect;
|
||||
public SkillInformationItem skillInfoPrefab;
|
||||
public List<RectTransform> uiPrefabList = new List<RectTransform>();
|
||||
public List<SkillInformationItem> createSkillInfo = new List<SkillInformationItem>();
|
||||
|
||||
public Button settingButton;
|
||||
|
||||
|
||||
private int selectedSlotIndex = -1;
|
||||
private string selectedSkillId = null;
|
||||
private int playerLevel;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
playerLevel = PlayerDataManager.Singleton.player.level;
|
||||
|
||||
SetSkillSlots();
|
||||
SetSkillInfoItem();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (selectedSlotIndex != -1 && !string.IsNullOrWhiteSpace(selectedSkillId))
|
||||
{
|
||||
settingButton.interactable = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
settingButton.interactable = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetSkillSlots()
|
||||
@@ -39,15 +68,102 @@ namespace TON
|
||||
|
||||
if (i < activatedSkills.Count) // 해당 인덱스에 활성화된 스킬이 있을 경우
|
||||
{
|
||||
newSkillSlot.Initalize(activatedSkills[i].SkillData.id);
|
||||
newSkillSlot.Initalize(activatedSkills[i].SkillData.id, i);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 복제 됐을때 기본 상태가 잠금 상태
|
||||
newSkillSlot.GetComponent<Button>().interactable = false;
|
||||
}
|
||||
|
||||
createSkillSlots.Add(newSkillSlot);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetSkillInfoItem()
|
||||
{
|
||||
List<SkillData> skillDatas = SkillDataManager.Singleton.skillDatas;
|
||||
|
||||
float y = 0;
|
||||
for (int i = 0; i < skillDatas.Count; i++)
|
||||
{
|
||||
SkillData skillData = skillDatas[i];
|
||||
SkillInformationItem skillInfoItem = Instantiate(skillInfoPrefab, scrollRect.content);
|
||||
|
||||
skillInfoItem.gameObject.SetActive(true);
|
||||
skillInfoItem.Initalize(skillData, playerLevel);
|
||||
createSkillInfo.Add(skillInfoItem);
|
||||
|
||||
if (playerLevel < skillData.requiredLevel)
|
||||
{
|
||||
skillInfoItem.GetComponent<Button>().interactable = false;
|
||||
}
|
||||
|
||||
RectTransform rectTransform = skillInfoItem.GetComponent<RectTransform>();
|
||||
|
||||
uiPrefabList.Add(rectTransform);
|
||||
uiPrefabList[i].anchoredPosition = new Vector2(0f, -y);
|
||||
y += uiPrefabList[i].sizeDelta.y;
|
||||
}
|
||||
|
||||
scrollRect.content.sizeDelta = new Vector2(scrollRect.content.sizeDelta.x, y);
|
||||
}
|
||||
|
||||
public void OnClickSkillSlot()
|
||||
{
|
||||
GameObject selectedSlotGameObject = EventSystem.current.currentSelectedGameObject;
|
||||
SkillSettingUI_SkillSlot selectedSlot = selectedSlotGameObject.GetComponent<SkillSettingUI_SkillSlot>();
|
||||
|
||||
selectedSlotIndex = selectedSlot.SelectedSlot();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (i != selectedSlotIndex)
|
||||
{
|
||||
createSkillSlots[i].UnselectedSlot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClickSkillInfo()
|
||||
{
|
||||
GameObject selectedSlotGameObject = EventSystem.current.currentSelectedGameObject;
|
||||
SkillInformationItem selectedSkillInfo = selectedSlotGameObject.GetComponent<SkillInformationItem>();
|
||||
|
||||
selectedSkillId = selectedSkillInfo.SelectedSkillInfo();
|
||||
foreach (var skillInfo in createSkillInfo)
|
||||
{
|
||||
if (skillInfo.skillId != selectedSkillId)
|
||||
{
|
||||
skillInfo.UnselectedSkillInfo();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClickSettingButton()
|
||||
{
|
||||
Debug.Log($"OnClickSettingButton() : {selectedSkillId} , {selectedSlotIndex}");
|
||||
// 스킬 데이터 업데이트 할때 selectedSlotIndex +1 해서 넘겨줘야함
|
||||
SkillDataManager.Singleton.UpdateSkillData(selectedSkillId, selectedSlotIndex + 1);
|
||||
|
||||
// 스킬 업데이트 후 UI 갱신
|
||||
var unselectedSkill = createSkillInfo.Find(skill => skill.skillId == selectedSkillId);
|
||||
unselectedSkill?.UnselectedSkillInfo();
|
||||
createSkillSlots[selectedSlotIndex].UnselectedSlot();
|
||||
|
||||
selectedSkillId = null;
|
||||
selectedSlotIndex = -1;
|
||||
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
private void RefreshUI()
|
||||
{
|
||||
SetSkillSlots();
|
||||
SetSkillInfoItem();
|
||||
}
|
||||
|
||||
public void OnClickCloseButton()
|
||||
{
|
||||
UIManager.Hide<SkillSettingUI>(UIList.SkillSettingUI);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user