2024-09-24 10:09:17 +00:00
|
|
|
using System.Collections;
|
2024-11-17 04:29:57 +00:00
|
|
|
using System.Collections.Generic;
|
2024-12-06 13:20:10 +00:00
|
|
|
using BlueWater.Audios;
|
2024-09-24 10:09:17 +00:00
|
|
|
using BlueWater.Tycoons;
|
2024-09-12 04:17:34 +00:00
|
|
|
using Sirenix.OdinInspector;
|
2024-09-09 09:50:37 +00:00
|
|
|
using UnityEngine;
|
2024-12-16 11:25:27 +00:00
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
using UnityEngine.InputSystem;
|
2024-11-26 08:18:41 +00:00
|
|
|
using UnityEngine.UI;
|
2024-09-09 09:50:37 +00:00
|
|
|
|
|
|
|
namespace BlueWater.Uis
|
|
|
|
{
|
2024-12-18 16:00:39 +00:00
|
|
|
public class TycoonSelectCard : PausePopupUi
|
2024-09-09 09:50:37 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
[SerializeField]
|
2024-10-24 08:05:32 +00:00
|
|
|
private GameObject _panel;
|
2024-09-12 04:17:34 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
[SerializeField]
|
|
|
|
private Transform _contents;
|
2024-12-06 13:20:10 +00:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private string _openSfxName = "OpenNormalRewardBox";
|
2024-12-18 16:00:39 +00:00
|
|
|
|
|
|
|
[Title("참조")]
|
|
|
|
[SerializeField]
|
|
|
|
private UiEventsController _uiEventsController;
|
2024-10-28 09:09:18 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
private List<TycoonCard> _tycoonCards = new(3);
|
2024-10-24 08:05:32 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
private LevelData _currentLevelData;
|
|
|
|
private TycoonManager _tycoonManager;
|
|
|
|
private TycoonCardController _tycoonCardController;
|
2024-10-03 07:55:56 +00:00
|
|
|
|
2024-12-16 11:25:27 +00:00
|
|
|
private InputAction _interactionEAction;
|
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
private void Start()
|
2024-09-24 10:09:17 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
_panel.SetActive(false);
|
|
|
|
|
2024-12-16 11:25:27 +00:00
|
|
|
_interactionEAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.InteractionE);
|
|
|
|
|
2024-11-05 12:27:46 +00:00
|
|
|
_tycoonManager = TycoonManager.Instance;
|
2024-11-17 04:29:57 +00:00
|
|
|
_tycoonCardController = _tycoonManager.TycoonCardController;
|
|
|
|
|
|
|
|
EventManager.OnOpenedNormalRewardBox += CreateCard;
|
2024-09-24 10:09:17 +00:00
|
|
|
}
|
|
|
|
|
2024-10-08 06:45:46 +00:00
|
|
|
private void OnDestroy()
|
|
|
|
{
|
2024-11-11 09:51:12 +00:00
|
|
|
EventManager.OnOpenedNormalRewardBox -= CreateCard;
|
2024-12-16 11:25:27 +00:00
|
|
|
|
|
|
|
if (_interactionEAction != null)
|
|
|
|
{
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
|
|
|
}
|
2024-10-08 06:45:46 +00:00
|
|
|
}
|
2024-10-29 10:43:07 +00:00
|
|
|
|
|
|
|
public override void Open()
|
|
|
|
{
|
2024-12-18 16:00:39 +00:00
|
|
|
OpenSwitch(InputActionMaps.TycoonUi);
|
2024-12-06 13:20:10 +00:00
|
|
|
AudioManager.Instance.PlaySfx(_openSfxName, ignoreTimeScale: true);
|
2024-11-17 04:29:57 +00:00
|
|
|
_panel.SetActive(true);
|
2024-10-29 10:43:07 +00:00
|
|
|
}
|
2024-10-08 06:45:46 +00:00
|
|
|
|
2024-10-29 10:43:07 +00:00
|
|
|
public override void Close()
|
2024-09-12 04:17:34 +00:00
|
|
|
{
|
2024-12-18 16:00:39 +00:00
|
|
|
CloseSwitch(InputActionMaps.Tycoon);
|
2024-11-17 04:29:57 +00:00
|
|
|
_panel.SetActive(false);
|
2024-12-20 05:11:56 +00:00
|
|
|
EventSystem.current.SetSelectedGameObject(null);
|
2024-10-29 10:43:07 +00:00
|
|
|
}
|
2024-12-16 11:25:27 +00:00
|
|
|
|
|
|
|
public override void EnableInput()
|
|
|
|
{
|
|
|
|
_interactionEAction.performed += OnInteractionE;
|
2024-12-18 16:00:39 +00:00
|
|
|
_uiEventsController.EnableAutoNavigate();
|
2024-12-16 11:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void DisableInput()
|
|
|
|
{
|
|
|
|
_interactionEAction.performed -= OnInteractionE;
|
2024-12-18 16:00:39 +00:00
|
|
|
_uiEventsController.DisableAutoNavigate();
|
2024-12-16 11:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnInteractionE(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
var current = EventSystem.current.currentSelectedGameObject;
|
|
|
|
if (!current) return;
|
|
|
|
|
|
|
|
var currenButton = current.GetComponent<Button>();
|
|
|
|
currenButton.onClick.Invoke();
|
|
|
|
}
|
|
|
|
|
2024-10-29 10:43:07 +00:00
|
|
|
[Button("카드 생성하기(레벨업)")]
|
|
|
|
private void CreateCard()
|
|
|
|
{
|
2024-11-26 08:18:41 +00:00
|
|
|
var panelcolor = _panel.GetComponent<Image>().color;
|
|
|
|
panelcolor.a = 0;
|
|
|
|
_panel.GetComponent<Image>().color = panelcolor;
|
|
|
|
|
2024-10-29 10:43:07 +00:00
|
|
|
if (!Application.isPlaying) return;
|
2024-10-03 07:55:56 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
_currentLevelData = TycoonManager.Instance.GetCurrentLevelData();
|
|
|
|
_tycoonCardController.DestroyCardList(_tycoonCards);
|
|
|
|
for (int i = 0; i < _tycoonCards.Capacity; i++)
|
2024-09-12 04:17:34 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
var newCard = _tycoonCardController.CreateTycoonCard(_contents);
|
|
|
|
newCard.SetName($"Card{i:00}");
|
2024-12-03 07:54:12 +00:00
|
|
|
newCard.transform.localScale = new Vector3(0.9f, 0.9f, 0.9f);
|
2024-11-17 04:29:57 +00:00
|
|
|
_tycoonCards.Add(newCard);
|
2024-09-12 04:17:34 +00:00
|
|
|
}
|
2024-10-24 08:05:32 +00:00
|
|
|
|
2024-10-29 10:43:07 +00:00
|
|
|
Open();
|
2024-09-24 10:09:17 +00:00
|
|
|
|
|
|
|
//----카드 값 지정 및 초기화----
|
2024-11-17 04:29:57 +00:00
|
|
|
HashSet<string> hashSet = new HashSet<string>(_tycoonCards.Capacity - 1);
|
|
|
|
foreach (var element in _tycoonCards)
|
2024-09-24 10:09:17 +00:00
|
|
|
{
|
2024-11-28 23:07:50 +00:00
|
|
|
CardNormalData cardNormalData = null;
|
2024-11-17 04:29:57 +00:00
|
|
|
CardData cardData = null;
|
|
|
|
string cardIdx = null;
|
2024-10-10 05:41:47 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
do
|
2024-10-10 05:41:47 +00:00
|
|
|
{
|
2024-11-28 23:07:50 +00:00
|
|
|
cardNormalData = _tycoonCardController.CardNormalDataSo.GetRandomCardData();
|
|
|
|
cardIdx = cardNormalData.Idx;
|
|
|
|
cardNormalData = _tycoonCardController.CardNormalDataSo.SubstitutionLiquid(cardNormalData, _currentLevelData);
|
|
|
|
cardData = _tycoonCardController.CardDataSo.GetDataByIdx(cardIdx);
|
|
|
|
} while (cardNormalData == null || _tycoonCardController.CardMaxCheck(cardData) || hashSet.Contains(cardIdx));
|
2024-11-17 04:29:57 +00:00
|
|
|
|
|
|
|
hashSet.Add(cardIdx);
|
|
|
|
element.SetCard(cardData);
|
|
|
|
element.SetSelectAction(SelectedCard);
|
|
|
|
element.Rotation_Start();
|
2024-11-26 08:18:41 +00:00
|
|
|
|
|
|
|
StartCoroutine(FadeInPanel());
|
2024-10-03 07:55:56 +00:00
|
|
|
}
|
2024-12-16 11:25:27 +00:00
|
|
|
|
2024-12-18 16:00:39 +00:00
|
|
|
_uiEventsController.SetSelectObject(_tycoonCards[0].CardArea.gameObject);
|
2024-11-17 04:29:57 +00:00
|
|
|
}
|
2024-12-16 11:25:27 +00:00
|
|
|
|
2024-11-26 08:18:41 +00:00
|
|
|
private IEnumerator FadeInPanel()
|
|
|
|
{
|
|
|
|
float time = 0.0f; // 타이머 초기화
|
|
|
|
|
|
|
|
while (time < 1.0f)
|
|
|
|
{
|
|
|
|
time += Time.unscaledDeltaTime; // 시간 업데이트
|
|
|
|
|
|
|
|
float _FadeTime = time / 1.0f;
|
|
|
|
|
|
|
|
var panelcolor = _panel.GetComponent<Image>().color;
|
|
|
|
panelcolor.a = Mathf.Lerp(0.0f, 0.9f, _FadeTime);
|
|
|
|
_panel.GetComponent<Image>().color = panelcolor;
|
|
|
|
|
|
|
|
yield return null;
|
|
|
|
}
|
2024-12-16 11:25:27 +00:00
|
|
|
|
|
|
|
// _tycoonCards[1].CardArea.OnSelect(null);
|
2024-11-26 08:18:41 +00:00
|
|
|
}
|
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
private void SelectedCard(TycoonCard currentTycoonCard)
|
|
|
|
{
|
2024-12-16 11:25:27 +00:00
|
|
|
DisableInput();
|
2024-11-28 23:07:50 +00:00
|
|
|
_tycoonCardController.SelectCard(currentTycoonCard);
|
2024-11-17 04:29:57 +00:00
|
|
|
currentTycoonCard.CardArea.SuccessClick();
|
|
|
|
StartCoroutine(SelectedAnimation(currentTycoonCard));
|
2024-09-09 09:50:37 +00:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:55:56 +00:00
|
|
|
// ReSharper disable Unity.PerformanceAnalysis
|
2024-11-17 04:29:57 +00:00
|
|
|
private IEnumerator SelectedAnimation(TycoonCard currentTycoonCard)
|
2024-09-09 09:50:37 +00:00
|
|
|
{
|
2024-11-19 06:57:50 +00:00
|
|
|
Vector3 startScale01 = default; //시작 위치
|
|
|
|
Vector3 startScale02 = default; //시작 위치
|
|
|
|
Vector3 startScale03 = default; //시작 위치
|
2024-09-24 10:09:17 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
RectTransform rect01 = null;
|
|
|
|
RectTransform rect02 = null;
|
|
|
|
RectTransform rect03 = null;
|
2024-09-24 10:09:17 +00:00
|
|
|
|
2024-10-03 07:55:56 +00:00
|
|
|
// 화면의 해상도를 가져옴
|
2024-11-26 08:18:41 +00:00
|
|
|
if (currentTycoonCard == _tycoonCards[0])
|
2024-09-24 10:09:17 +00:00
|
|
|
{
|
2024-11-19 06:57:50 +00:00
|
|
|
rect01 = _tycoonCards[1].RectTransform;
|
2024-11-17 04:29:57 +00:00
|
|
|
rect02 = _tycoonCards[2].RectTransform;
|
2024-11-19 06:57:50 +00:00
|
|
|
rect03 = _tycoonCards[0].RectTransform;
|
2024-10-03 07:55:56 +00:00
|
|
|
}
|
2024-11-26 08:18:41 +00:00
|
|
|
else if (currentTycoonCard == _tycoonCards[1])
|
2024-10-03 07:55:56 +00:00
|
|
|
{
|
2024-11-19 06:57:50 +00:00
|
|
|
rect01 = _tycoonCards[0].RectTransform;
|
2024-11-17 04:29:57 +00:00
|
|
|
rect02 = _tycoonCards[2].RectTransform;
|
2024-11-19 06:57:50 +00:00
|
|
|
rect03 = _tycoonCards[1].RectTransform;
|
2024-10-03 07:55:56 +00:00
|
|
|
}
|
2024-11-26 08:18:41 +00:00
|
|
|
else if (currentTycoonCard == _tycoonCards[2])
|
2024-10-03 07:55:56 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
rect01 = _tycoonCards[0].RectTransform;
|
|
|
|
rect02 = _tycoonCards[1].RectTransform;
|
2024-11-19 06:57:50 +00:00
|
|
|
rect03 = _tycoonCards[2].RectTransform;
|
2024-10-03 07:55:56 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 06:57:50 +00:00
|
|
|
rect03.localScale = new Vector3(1.5f, 1.5f, 1.5f);
|
|
|
|
|
|
|
|
startScale01 = rect01.localScale; // 시작 위치
|
|
|
|
startScale02 = rect02.localScale; // 시작 위치
|
|
|
|
startScale03 = rect03.localScale; // 시작 위치
|
|
|
|
|
|
|
|
|
2024-10-03 07:55:56 +00:00
|
|
|
float time = 0.0f; // 타이머 초기화
|
|
|
|
|
2024-12-16 11:25:27 +00:00
|
|
|
while (time < 0.5f)
|
2024-10-03 07:55:56 +00:00
|
|
|
{
|
|
|
|
time += Time.unscaledDeltaTime; // 시간 업데이트
|
|
|
|
|
2024-11-19 06:57:50 +00:00
|
|
|
float _Time = time / 0.5f;
|
|
|
|
float easedTOut = EaseEffect.ExpoOut(_Time);
|
|
|
|
|
|
|
|
rect01.localScale = Vector3.Lerp(startScale01, new Vector3(0.0f, 0.0f, 0.0f), easedTOut);
|
|
|
|
rect02.localScale = Vector3.Lerp(startScale02, new Vector3(0.0f, 0.0f, 0.0f), easedTOut);
|
|
|
|
rect03.localScale = Vector3.Lerp(startScale03, new Vector3(1.0f, 1.0f, 1.0f), easedTOut);
|
|
|
|
|
2024-11-26 08:18:41 +00:00
|
|
|
|
2024-11-19 06:57:50 +00:00
|
|
|
yield return null;
|
|
|
|
}
|
2024-09-09 09:50:37 +00:00
|
|
|
|
2024-11-19 06:57:50 +00:00
|
|
|
time = 0.0f; // 타이머 초기화
|
|
|
|
startScale03 = rect03.localScale; // 시작 위치
|
|
|
|
|
2024-12-16 11:25:27 +00:00
|
|
|
while (time < 0.5f)
|
2024-11-19 06:57:50 +00:00
|
|
|
{
|
|
|
|
time += Time.unscaledDeltaTime; // 시간 업데이트
|
|
|
|
|
2024-12-16 11:25:27 +00:00
|
|
|
float _Time = time / 0.25f;
|
|
|
|
float _FadeTime = time / 0.5f;
|
2024-10-03 07:55:56 +00:00
|
|
|
|
2024-11-19 06:57:50 +00:00
|
|
|
float easedTIn = EaseEffect.ExpoIn(_Time);
|
|
|
|
rect03.localScale = Vector3.Lerp(startScale03, new Vector3(0.0f, 0.0f, 0.0f), easedTIn);
|
2024-10-03 07:55:56 +00:00
|
|
|
|
2024-11-26 08:18:41 +00:00
|
|
|
var panelcolor = _panel.GetComponent<Image>().color;
|
|
|
|
panelcolor.a = Mathf.Lerp(0.9f, 0.0f, _FadeTime);
|
|
|
|
_panel.GetComponent<Image>().color = panelcolor;
|
2024-10-03 07:55:56 +00:00
|
|
|
yield return null;
|
2024-09-24 10:09:17 +00:00
|
|
|
}
|
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
_tycoonCardController.DestroyCardList(_tycoonCards);
|
2024-10-29 10:43:07 +00:00
|
|
|
Close();
|
2024-09-09 09:50:37 +00:00
|
|
|
}
|
2024-12-16 11:25:27 +00:00
|
|
|
|
2024-09-09 09:50:37 +00:00
|
|
|
}
|
|
|
|
}
|