CapersProject/Assets/02.Scripts/Ui/Tycoon/TycoonSelectCard.cs

164 lines
5.7 KiB
C#
Raw Normal View History

2024-09-24 10:09:17 +00:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using BlueWater.Tycoons;
using Mono.Cecil.Cil;
2024-09-12 04:17:34 +00:00
using Sirenix.OdinInspector;
2024-09-09 09:50:37 +00:00
using UnityEngine;
namespace BlueWater.Uis
{
public class TycoonSelectCard : MonoBehaviour
{
2024-09-12 04:17:34 +00:00
2024-09-24 10:09:17 +00:00
private Camera mainCamera;
2024-09-12 04:17:34 +00:00
[field: SerializeField, CLabel("카드 1")]
2024-09-12 07:38:16 +00:00
private GameObject card01;
2024-09-12 04:17:34 +00:00
[field: SerializeField, CLabel("카드 2")]
2024-09-12 07:38:16 +00:00
private GameObject card02;
2024-09-12 04:17:34 +00:00
[field: SerializeField, CLabel("카드 3")]
2024-09-12 07:38:16 +00:00
private GameObject card03;
2024-09-12 04:17:34 +00:00
2024-09-12 07:38:16 +00:00
private GameObject _currentCard01;
private GameObject _currentCard02;
private GameObject _currentCard03;
2024-09-12 04:17:34 +00:00
2024-09-12 07:38:16 +00:00
private TycoonCard _tycoonCard01Componet;
private TycoonCard _tycoonCard02Componet;
private TycoonCard _tycoonCard03Componet;
2024-09-12 04:17:34 +00:00
2024-09-24 10:09:17 +00:00
void Start()
{
mainCamera = TycoonCameraManager.Instance.MainCamera;
}
2024-09-12 04:17:34 +00:00
[Button("카드 생성하기(레벨업)")]
private void CreateCard()
{
if (!Application.isPlaying) return;
// 기존 카드가 있으면 삭제
2024-09-12 07:38:16 +00:00
if (_currentCard01 != null)
2024-09-12 04:17:34 +00:00
{
2024-09-12 07:38:16 +00:00
Destroy(_currentCard01);
2024-09-12 04:17:34 +00:00
}
2024-09-12 07:38:16 +00:00
if (_currentCard02 != null)
2024-09-12 04:17:34 +00:00
{
2024-09-12 07:38:16 +00:00
Destroy(_currentCard02);
2024-09-12 04:17:34 +00:00
}
2024-09-12 07:38:16 +00:00
if (_currentCard03 != null)
2024-09-12 04:17:34 +00:00
{
2024-09-12 07:38:16 +00:00
Destroy(_currentCard03);
2024-09-12 04:17:34 +00:00
}
2024-09-12 07:38:16 +00:00
_currentCard01 = Instantiate(card01, this.transform);
_currentCard01.name = "Card";
2024-09-12 04:17:34 +00:00
2024-09-12 07:38:16 +00:00
_currentCard02 = Instantiate(card02, this.transform);
_currentCard02.name = "Card02";
2024-09-12 04:17:34 +00:00
2024-09-12 07:38:16 +00:00
_currentCard03 = Instantiate(card03, this.transform);
_currentCard03.name = "Card03";
2024-09-12 04:17:34 +00:00
2024-09-12 07:38:16 +00:00
_currentCard01.transform.localPosition = new Vector3(-550, 0, 0);
_currentCard02.transform.localPosition = new Vector3(0, 0, 0);
_currentCard03.transform.localPosition = new Vector3(550, 0, 0);
2024-09-12 04:17:34 +00:00
2024-09-12 07:38:16 +00:00
_tycoonCard01Componet = _currentCard01.GetComponent<TycoonCard>();
_tycoonCard02Componet = _currentCard02.GetComponent<TycoonCard>();
_tycoonCard03Componet = _currentCard03.GetComponent<TycoonCard>();
2024-09-24 10:09:17 +00:00
//----카드 값 지정 및 초기화----
CardData card;
var card01Key = "NULL VAL";
do
{
card = TycoonManager.Instance.CardDataSo.GetRandCardData();
card01Key = card.Idx;
} while (TycoonManager.Instance.CardDataSo.CardMaxCheck(card));
_tycoonCard01Componet.SetCard(card01Key);
var card02Key = "NULL VAL";
do
{
card = TycoonManager.Instance.CardDataSo.GetRandCardData();
card02Key = card.Idx;
} while (TycoonManager.Instance.CardDataSo.CardMaxCheck(card) || card02Key.Equals(card01Key));
_tycoonCard02Componet.SetCard(card02Key);
var card03Key = "NULL VAL";
do
{
card = TycoonManager.Instance.CardDataSo.GetRandCardData();
card03Key = card.Idx;
} while (TycoonManager.Instance.CardDataSo.CardMaxCheck(card) || card03Key.Equals(card01Key) || card03Key.Equals(card02Key));
_tycoonCard03Componet.SetCard(card03Key);
//-------------
2024-09-12 04:17:34 +00:00
2024-09-12 07:38:16 +00:00
_tycoonCard01Componet.Rotation_Start();
_tycoonCard02Componet.Rotation_Start();
_tycoonCard03Componet.Rotation_Start();
2024-09-24 10:09:17 +00:00
}
public void SelectedCard(TycoonCard currTycoonCard)
2024-09-09 09:50:37 +00:00
{
2024-09-24 10:09:17 +00:00
SelectedAnimation(currTycoonCard);
2024-09-09 09:50:37 +00:00
}
2024-09-24 10:09:17 +00:00
private IEnumerator SelectedAnimation(TycoonCard currTycoonCard)
2024-09-09 09:50:37 +00:00
{
2024-09-24 10:09:17 +00:00
// 화면의 해상도를 가져옴
float screenWidth = Screen.width;
float screenHeight = Screen.height;
// 오브젝트를 월드 좌표로 변환
Vector3 leftOffScreenPosition = Camera.main.ScreenToWorldPoint(new Vector3(-500, screenHeight / 2, Camera.main.nearClipPlane));
Vector3 rightOffScreenPosition = Camera.main.ScreenToWorldPoint(new Vector3(screenWidth + 500, screenHeight / 2, Camera.main.nearClipPlane));
// 현재 위치를 가져옴
Vector3 leftStartPosition = _tycoonCard02Componet.transform.position;
Vector3 rightStartPosition = _tycoonCard03Componet.transform.position;
// 일정 시간 동안 오브젝트를 이동
float elapsedTime = 0;
while (elapsedTime < 2f)
{
elapsedTime += Time.deltaTime;
2024-09-09 09:50:37 +00:00
2024-09-24 10:09:17 +00:00
// Ease Expo Out 계산 (t는 0에서 1 사이의 값)
float t = elapsedTime / 2f;
float easeValue = 1 - Mathf.Pow(2, -10 * t);
// 양쪽 오브젝트를 각각 이동
_tycoonCard02Componet.transform.position = Vector3.Lerp(leftStartPosition, leftOffScreenPosition, easeValue);
_tycoonCard03Componet.transform.position = Vector3.Lerp(rightStartPosition, rightOffScreenPosition, easeValue);
yield return null; // 한 프레임 대기
}
// 오브젝트 최종 위치 설정 (정확한 끝 위치 보장)
_tycoonCard02Componet.transform.position = leftOffScreenPosition;
_tycoonCard03Componet.transform.position = rightOffScreenPosition;
2024-09-09 09:50:37 +00:00
}
2024-09-24 10:09:17 +00:00
private void Awake()
2024-09-09 09:50:37 +00:00
{
2024-09-24 10:09:17 +00:00
2024-09-09 09:50:37 +00:00
}
2024-09-24 10:09:17 +00:00
2024-09-09 09:50:37 +00:00
}
}