using UnityEngine; using UnityEngine.UI; using CodeJay.Classes; using UnityEngine.ResourceManagement.AsyncOperations; using BansheeGz.BGDatabase; using UnityEngine.EventSystems; public class HuntingSlot : MonoBehaviour { [SerializeField] private TMPro.TextMeshProUGUI NameTMP; [Space(20)] [SerializeField] private Image AI_Left; [SerializeField] private Image AI_Right; [SerializeField] private Image Frame_Left; [SerializeField] private Image Frame_Right; [SerializeField] private Image Block_Left; [SerializeField] private Image Block_Right; [SerializeField] private Image Block_Lock_Left; [SerializeField] private Image Block_Lock_Right; [SerializeField] private Image Block_Heart_Left; [SerializeField] private Image Block_Heart_Right; [SerializeField] private GameObject ClearGO_Left; [SerializeField] private GameObject ClearGO_Right; [SerializeField] private GameObject[] Right_GOs; [SerializeField] private ScrollRect sr; private bool _fullview_Left = false; private bool _fullview_Right = false; private HuntingData _data_left; private HuntingData _data_right; private DB_HuntingData _huntigdata_left; private DB_HuntingData _huntigdata_right; private BGId _huntingListID; public void SetData(int index, int unlockTargetIndex) { DB_HuntingListData huntingListData = DB_HuntingListData.GetEntity(Mathf.FloorToInt((float)((float)index / 2.0f))); _huntingListID = huntingListData.Id; _data_left = GameManager.DB.GetHuntingData(index); _data_right = GameManager.DB.GetHuntingData(index + 1); _huntigdata_left = DB_HuntingData.GetEntity(new BansheeGz.BGDatabase.BGId(_data_left.HuntingDataID)); if (GameManager.BGDatabase.LoadUnlockHuntingImageHandle[_huntigdata_left.GetDBF_UnlockImageAddressablesAddress()].Status == AsyncOperationStatus.Succeeded) { AI_Left.sprite = GameManager.BGDatabase.LoadUnlockHuntingImageHandle[_huntigdata_left.GetDBF_UnlockImageAddressablesAddress()].Result as Sprite; } NameTMP.text = huntingListData.DBF_Title; //NameTMP.text = $"{huntingListData.DBF_Title}\n{_data_left.Name}"; //AI_Left.sprite = GameManager.Resource.GetAISpriteFromResources(_data_left.TextureIndex); if (_data_right == null) { for (int i = 0; i < Right_GOs.Length; i++) Right_GOs[i].SetActive(false); } else { for (int i = 0; i < Right_GOs.Length; i++) Right_GOs[i].SetActive(true); _huntigdata_right = DB_HuntingData.GetEntity(new BansheeGz.BGDatabase.BGId(_data_right.HuntingDataID)); if (GameManager.BGDatabase.LoadUnlockHuntingImageHandle[_huntigdata_right.GetDBF_UnlockImageAddressablesAddress()].Status == AsyncOperationStatus.Succeeded) { AI_Right.sprite = GameManager.BGDatabase.LoadUnlockHuntingImageHandle[_huntigdata_right.GetDBF_UnlockImageAddressablesAddress()].Result as Sprite; } //AI_Right.sprite = GameManager.Resource.GetAISpriteFromResources(_data_right.TextureIndex); } // 도달 못함 if (GameManager.DB.IsAllUnlocked()) { _fullview_Left = true; _fullview_Right = true; ClearGO_Left.SetActive(true); ClearGO_Right.SetActive(true); Frame_Left.enabled = false; Frame_Right.enabled = false; Block_Lock_Left.enabled = false; Block_Lock_Right.enabled = false; Block_Heart_Left.enabled = false; Block_Heart_Right.enabled = false; Block_Left.enabled = false; Block_Right.enabled = false; } else if (_data_left.Index > unlockTargetIndex) { _fullview_Left = false; _fullview_Right = false; ClearGO_Left.SetActive(false); Frame_Left.enabled = false; Block_Left.enabled = true; Block_Lock_Left.enabled = true; Block_Heart_Left.enabled = false; if (_data_right != null) { ClearGO_Right.SetActive(false); Frame_Right.enabled = false; Block_Right.enabled = true; Block_Lock_Right.enabled = true; Block_Heart_Right.enabled = false; } } else if (_data_left.Index == unlockTargetIndex) { // 1단계 클리어 해야함 _fullview_Left = false; _fullview_Right = false; ClearGO_Left.SetActive(false); Frame_Left.enabled = true; Block_Left.enabled = true; Block_Lock_Left.enabled = false; Block_Heart_Left.enabled = true; if (_data_right != null) { ClearGO_Right.SetActive(false); Frame_Right.enabled = false; Block_Right.enabled = true; Block_Lock_Right.enabled = true; Block_Heart_Right.enabled = false; } } else if (_data_right != null) { // 2단계 클리어 해야함 // 두 if문 조건 교체 (복구) if (_data_right.Index == unlockTargetIndex) { _fullview_Left = true; _fullview_Right = false; ClearGO_Left.SetActive(true); Frame_Left.enabled = false; Block_Left.enabled = false; Block_Lock_Left.enabled = false; Block_Heart_Left.enabled = false; ClearGO_Right.SetActive(false); Frame_Right.enabled = true; Block_Right.enabled = true; Block_Lock_Right.enabled = false; Block_Heart_Right.enabled = true; } else if (_data_right.Index < unlockTargetIndex) { _fullview_Left = true; _fullview_Right = true; ClearGO_Left.SetActive(true); ClearGO_Right.SetActive(true); Frame_Left.enabled = false; Frame_Right.enabled = false; Block_Left.enabled = false; Block_Right.enabled = false; Block_Lock_Left.enabled = false; Block_Lock_Right.enabled = false; Block_Heart_Left.enabled = false; Block_Heart_Right.enabled = false; } } // 왼쪽 데이터만 있고(총 데이터가 홀수일 경우) 클리어함 else { _fullview_Left = true; _fullview_Right = false; ClearGO_Left.SetActive(true); Frame_Left.enabled = false; Block_Left.enabled = false; Block_Lock_Left.enabled = false; Block_Heart_Left.enabled = false; } } public void ClickAIImage(bool isLeft) { GameManager.Sound.PlaySFX(ESFXType.Button_Hit); if (isLeft) { if (_fullview_Left) GameManager.Event.InvokeEvent(EEventType.OnClickFullView, new BGId(_data_left.HuntingDataID), _huntingListID); } else { if (_data_right != null && _fullview_Right) GameManager.Event.InvokeEvent(EEventType.OnClickFullView, new BGId(_data_right.HuntingDataID), _huntingListID); } } public void OnBeginDrag(PointerEventData eventData) { sr.OnBeginDrag(eventData); } public void OnDrag(PointerEventData eventData) { sr.OnDrag(eventData); } public void OnEndDrag(PointerEventData eventData) { sr.OnEndDrag(eventData); } }