207 lines
7.5 KiB
C#
207 lines
7.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BlueWater.Tycoons;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class TycoonSelectCard : PopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private Transform _contents;
|
|
|
|
private List<TycoonCard> _tycoonCards = new(3);
|
|
|
|
private LevelData _currentLevelData;
|
|
private TycoonManager _tycoonManager;
|
|
private TycoonCardController _tycoonCardController;
|
|
|
|
private void Start()
|
|
{
|
|
_panel.SetActive(false);
|
|
|
|
_tycoonManager = TycoonManager.Instance;
|
|
_tycoonCardController = _tycoonManager.TycoonCardController;
|
|
|
|
EventManager.OnOpenedNormalRewardBox += CreateCard;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventManager.OnOpenedNormalRewardBox -= CreateCard;
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
|
|
PopupUiController.RegisterPopup(this);
|
|
_panel.SetActive(true);
|
|
IsOpened = true;
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
_panel.SetActive(false);
|
|
PopupUiController.UnregisterPopup(this);
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.Tycoon);
|
|
IsOpened = false;
|
|
VisualFeedbackManager.Instance.ResetTimeScale();
|
|
}
|
|
|
|
[Button("카드 생성하기(레벨업)")]
|
|
private void CreateCard()
|
|
{
|
|
var panelcolor = _panel.GetComponent<Image>().color;
|
|
panelcolor.a = 0;
|
|
_panel.GetComponent<Image>().color = panelcolor;
|
|
|
|
if (!Application.isPlaying) return;
|
|
|
|
_currentLevelData = TycoonManager.Instance.GetCurrentLevelData();
|
|
_tycoonCardController.DestroyCardList(_tycoonCards);
|
|
for (int i = 0; i < _tycoonCards.Capacity; i++)
|
|
{
|
|
var newCard = _tycoonCardController.CreateTycoonCard(_contents);
|
|
newCard.SetName($"Card{i:00}");
|
|
_tycoonCards.Add(newCard);
|
|
}
|
|
|
|
Open();
|
|
|
|
//----카드 값 지정 및 초기화----
|
|
HashSet<string> hashSet = new HashSet<string>(_tycoonCards.Capacity - 1);
|
|
foreach (var element in _tycoonCards)
|
|
{
|
|
CardNormalData cardNormalData = null;
|
|
CardData cardData = null;
|
|
string cardIdx = null;
|
|
|
|
do
|
|
{
|
|
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));
|
|
|
|
hashSet.Add(cardIdx);
|
|
element.SetCard(cardData);
|
|
element.SetSelectAction(SelectedCard);
|
|
element.Rotation_Start();
|
|
|
|
StartCoroutine(FadeInPanel());
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
private void SelectedCard(TycoonCard currentTycoonCard)
|
|
{
|
|
_tycoonCardController.SelectCard(currentTycoonCard);
|
|
currentTycoonCard.CardArea.SuccessClick();
|
|
StartCoroutine(SelectedAnimation(currentTycoonCard));
|
|
}
|
|
|
|
// ReSharper disable Unity.PerformanceAnalysis
|
|
private IEnumerator SelectedAnimation(TycoonCard currentTycoonCard)
|
|
{
|
|
Vector3 startScale01 = default; //시작 위치
|
|
Vector3 startScale02 = default; //시작 위치
|
|
Vector3 startScale03 = default; //시작 위치
|
|
|
|
RectTransform rect01 = null;
|
|
RectTransform rect02 = null;
|
|
RectTransform rect03 = null;
|
|
|
|
// 화면의 해상도를 가져옴
|
|
if (currentTycoonCard == _tycoonCards[0])
|
|
{
|
|
rect01 = _tycoonCards[1].RectTransform;
|
|
rect02 = _tycoonCards[2].RectTransform;
|
|
rect03 = _tycoonCards[0].RectTransform;
|
|
}
|
|
else if (currentTycoonCard == _tycoonCards[1])
|
|
{
|
|
rect01 = _tycoonCards[0].RectTransform;
|
|
rect02 = _tycoonCards[2].RectTransform;
|
|
rect03 = _tycoonCards[1].RectTransform;
|
|
}
|
|
else if (currentTycoonCard == _tycoonCards[2])
|
|
{
|
|
rect01 = _tycoonCards[0].RectTransform;
|
|
rect02 = _tycoonCards[1].RectTransform;
|
|
rect03 = _tycoonCards[2].RectTransform;
|
|
}
|
|
|
|
rect03.localScale = new Vector3(1.5f, 1.5f, 1.5f);
|
|
|
|
startScale01 = rect01.localScale; // 시작 위치
|
|
startScale02 = rect02.localScale; // 시작 위치
|
|
startScale03 = rect03.localScale; // 시작 위치
|
|
|
|
|
|
float time = 0.0f; // 타이머 초기화
|
|
|
|
while (time < 1.0f)
|
|
{
|
|
time += Time.unscaledDeltaTime; // 시간 업데이트
|
|
|
|
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);
|
|
|
|
|
|
yield return null;
|
|
}
|
|
|
|
time = 0.0f; // 타이머 초기화
|
|
startScale03 = rect03.localScale; // 시작 위치
|
|
|
|
while (time < 1.0f)
|
|
{
|
|
time += Time.unscaledDeltaTime; // 시간 업데이트
|
|
|
|
float _Time = time / 0.5f;
|
|
float _FadeTime = time / 1.0f;
|
|
|
|
float easedTIn = EaseEffect.ExpoIn(_Time);
|
|
rect03.localScale = Vector3.Lerp(startScale03, new Vector3(0.0f, 0.0f, 0.0f), easedTIn);
|
|
|
|
var panelcolor = _panel.GetComponent<Image>().color;
|
|
panelcolor.a = Mathf.Lerp(0.9f, 0.0f, _FadeTime);
|
|
_panel.GetComponent<Image>().color = panelcolor;
|
|
yield return null;
|
|
}
|
|
|
|
_tycoonCardController.DestroyCardList(_tycoonCards);
|
|
Close();
|
|
}
|
|
}
|
|
}
|