181 lines
6.4 KiB
C#
181 lines
6.4 KiB
C#
|
|
using BansheeGz.BGDatabase;
|
|||
|
|
using CodeJay.Classes;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.EventSystems;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using UnityEngine.UIElements;
|
|||
|
|
|
|||
|
|
public class HuntingPanel : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
[SerializeField] private GameObject SlotPrefab;
|
|||
|
|
[SerializeField] private GameObject EmptySlotPrefab;
|
|||
|
|
[SerializeField] private Transform Content;
|
|||
|
|
[SerializeField] private TMPro.TextMeshProUGUI TitleTMP;
|
|||
|
|
[SerializeField] private GameObject[] Buttons;
|
|||
|
|
|
|||
|
|
private List<HuntingSlot> _lstSlots;
|
|||
|
|
|
|||
|
|
private void Awake()
|
|||
|
|
{
|
|||
|
|
// HuntingData하나에 2개의 데이터 필요함.
|
|||
|
|
// 100개라면 50개만 생성해야함 (왼쪽 오른쪽 있기때문)
|
|||
|
|
_lstSlots = new List<HuntingSlot>(DB_HuntingListData.CountEntities);
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 소수점이 나오면 데이터가 홀수로 끝난다는것이기 때문에
|
|||
|
|
// 오른쪽에 슬롯이 생성되지 않는것을 방지하기위해 올림을 한다.
|
|||
|
|
//int length = Mathf.CeilToInt(GameManager.DB.GetHuntingDataLength() / 2f);
|
|||
|
|
|
|||
|
|
// 헌팅 도전 슬롯 생성
|
|||
|
|
HuntingSlot slot = null;
|
|||
|
|
for (int i = 0; i < DB_HuntingListData.CountEntities; i++)
|
|||
|
|
{
|
|||
|
|
slot = Instantiate(SlotPrefab, Content).GetComponent<HuntingSlot>();
|
|||
|
|
_lstSlots.Add(slot);
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 하단 UI에 가려지는것을 방지하기 위한 프리팹.
|
|||
|
|
// 2개 생성하면 데이터의 길이가 4의 배수가 되지 않아도 홀수로 끝나도 위에까지 올라온다.
|
|||
|
|
Instantiate(EmptySlotPrefab, Content);
|
|||
|
|
Instantiate(EmptySlotPrefab, Content);
|
|||
|
|
|
|||
|
|
if (GameManager.Instance != null)
|
|||
|
|
{
|
|||
|
|
// 이벤트 매니저에 구독
|
|||
|
|
GameManager.Event.RegistEvent(EEventType.OnSynchronizeAIChllengeModeAIData, this.UpdateData);
|
|||
|
|
GameManager.Event.RegistEvent(EEventType.OnClickFullView, this.OnClickFullView);
|
|||
|
|
GameManager.Event.RegistEvent(EEventType.OnReturnFullView, this.OnReturnFullView);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void Start()
|
|||
|
|
{
|
|||
|
|
// 다른 스크립트들도 구독을 완료하고 난 뒤에 호출하도록
|
|||
|
|
// Start에서 슬롯을 업데이트한다.
|
|||
|
|
this.UpdateData();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnDestroy()
|
|||
|
|
{
|
|||
|
|
if (GameManager.Instance != null)
|
|||
|
|
{
|
|||
|
|
// 구독한 이벤트 해제
|
|||
|
|
GameManager.Event.RemoveEvent(EEventType.OnSynchronizeAIChllengeModeAIData, this.UpdateData);
|
|||
|
|
GameManager.Event.RemoveEvent(EEventType.OnClickFullView, this.OnClickFullView);
|
|||
|
|
GameManager.Event.RemoveEvent(EEventType.OnReturnFullView, this.OnReturnFullView);
|
|||
|
|
|
|||
|
|
GameManager.BGDatabase.ReleaseHuntingUnlockImage();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private void OnEnable()
|
|||
|
|
{
|
|||
|
|
GameManager.DB.CheckDayReset();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 슬롯들 업데이트 하는 함수
|
|||
|
|
private void UpdateData()
|
|||
|
|
{
|
|||
|
|
// 해금해야하는 인덱스를 가져온다.
|
|||
|
|
// 3번째까지(0 ~ 2) 클리어했으면 index 3을 가져온다.
|
|||
|
|
int unlockTargetIndex = GameManager.DB.GetUnlockTargetIndex();
|
|||
|
|
|
|||
|
|
// 헌팅 도전에 들어갈 데이터를 DB매니저에서 가져온다.
|
|||
|
|
HuntingData data = GameManager.DB.GetHuntingData(unlockTargetIndex);
|
|||
|
|
DB_HuntingListData huntingListData = DB_HuntingListData.GetEntity(GameManager.BGDatabase.GetNextLockHuntingListDataID());
|
|||
|
|
|
|||
|
|
// 모두 해금을 했는지 체크하기 위한
|
|||
|
|
if (GameManager.DB.IsAllUnlocked())
|
|||
|
|
{
|
|||
|
|
TitleTMP.text = "모두 해금 완료";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
string temp;
|
|||
|
|
if (huntingListData != null)
|
|||
|
|
{
|
|||
|
|
temp = $"Ep {unlockTargetIndex + 1}. {huntingListData.DBF_Title} (#{((unlockTargetIndex) % 2 + 1)} / #2)";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
temp = $"Ep {unlockTargetIndex + 1}. {data.Description} {data.Name} (#{((unlockTargetIndex) % 2 + 1)} / #2)";
|
|||
|
|
}
|
|||
|
|
temp += "\n<size=40>점 " + CodeJay.CodeJayUtility.Converter.MoneyToString(data.Stake);
|
|||
|
|
temp += "\n그녀의 남은 판돈 " + GameManager.DB.GetReaminingTargetConditionString(data.Index) + "</size>";
|
|||
|
|
TitleTMP.text = temp;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Data Length 100 == Slot Length 50
|
|||
|
|
for (int i = 0; i < _lstSlots.Count; i++)
|
|||
|
|
{
|
|||
|
|
_lstSlots[i].SetData(i * 2, unlockTargetIndex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnClickFullView(object huntingDataID, object huntingListDataID)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < Buttons.Length; i++)
|
|||
|
|
Buttons[i].SetActive(false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnReturnFullView()
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < Buttons.Length; i++)
|
|||
|
|
Buttons[i].SetActive(true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ClickUnlockNowButton()
|
|||
|
|
{
|
|||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
|||
|
|
|
|||
|
|
if (GameManager.DB.IsAllUnlocked() == false)
|
|||
|
|
{
|
|||
|
|
if (GameManager.DB.Key > 0)
|
|||
|
|
{
|
|||
|
|
GameManager.DB.SubKey(1, this.name);
|
|||
|
|
GameManager.DB.UnlockLastAIImage();
|
|||
|
|
GameManager.DB.SaveDatas();
|
|||
|
|
GameManager.Event.InvokeEvent(EEventType.OnSynchronizeAIChllengeModeAIData);
|
|||
|
|
|
|||
|
|
BGId huntingDataID = GameManager.BGDatabase.GetLastUnolockHuntingDataID();
|
|||
|
|
BGId huntingListDataID = GameManager.BGDatabase.GetLastUnolockHuntingListDataID();
|
|||
|
|
if (huntingDataID != BGId.Empty && huntingListDataID != BGId.Empty)
|
|||
|
|
{
|
|||
|
|
GameManager.Event.InvokeEvent(EEventType.OnClickFullView, huntingDataID, huntingListDataID);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
GameManager.UI.ShowNStackPopup(EPopupType.KeyChargePopup);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ClickChallenge()
|
|||
|
|
{
|
|||
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
|||
|
|
|
|||
|
|
if (GameManager.DB.IsAllUnlocked() == false)
|
|||
|
|
{
|
|||
|
|
if (GameManager.DB.Heart > 0)
|
|||
|
|
{
|
|||
|
|
if (GameManager.DB.Gold > 0)
|
|||
|
|
{
|
|||
|
|
GameManager.DB.SubHeart(1, this.name);
|
|||
|
|
GameManager.Event.InvokeEvent(EEventType.OnChallengeStart);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
GameManager.UI.ShowNStackPopup(EPopupType.GoldChargePopup);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
GameManager.UI.ShowNStackPopup(EPopupType.HeartChargePopup);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|