183 lines
6.5 KiB
C#
183 lines
6.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BlueWater.Tycoons;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
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()
|
|
{
|
|
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)
|
|
{
|
|
CardData cardData = null;
|
|
string cardIdx = null;
|
|
|
|
do
|
|
{
|
|
cardData = _tycoonManager.CardDataSo.GetRandCardData();
|
|
cardData = _tycoonManager.CardDataSo.SubstitutionLiquid(cardData, _currentLevelData);
|
|
|
|
if (cardData != null)
|
|
{
|
|
cardIdx = cardData.Idx;
|
|
}
|
|
|
|
} while (cardData == null || _tycoonManager.CardDataSo.CardMaxCheck(cardData) ||
|
|
hashSet.Contains(cardIdx) || _tycoonCardController.IsSelectedPassiveCard(cardData));
|
|
|
|
hashSet.Add(cardIdx);
|
|
element.SetCard(cardData);
|
|
element.SetSelectAction(SelectedCard);
|
|
element.Rotation_Start();
|
|
}
|
|
}
|
|
|
|
private void SelectedCard(TycoonCard currentTycoonCard)
|
|
{
|
|
_tycoonCardController.SelectedCard(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 easedTIn = EaseEffect.ExpoIn(_Time);
|
|
rect03.localScale = Vector3.Lerp(startScale03, new Vector3(0.0f, 0.0f, 0.0f), easedTIn);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
_tycoonCardController.DestroyCardList(_tycoonCards);
|
|
Close();
|
|
}
|
|
}
|
|
}
|