164 lines
5.7 KiB
C#
164 lines
5.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BlueWater.Tycoons;
|
|
using Mono.Cecil.Cil;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class TycoonSelectCard : MonoBehaviour
|
|
{
|
|
|
|
private Camera mainCamera;
|
|
|
|
[field: SerializeField, CLabel("카드 1")]
|
|
private GameObject card01;
|
|
[field: SerializeField, CLabel("카드 2")]
|
|
private GameObject card02;
|
|
[field: SerializeField, CLabel("카드 3")]
|
|
private GameObject card03;
|
|
|
|
private GameObject _currentCard01;
|
|
private GameObject _currentCard02;
|
|
private GameObject _currentCard03;
|
|
|
|
private TycoonCard _tycoonCard01Componet;
|
|
private TycoonCard _tycoonCard02Componet;
|
|
private TycoonCard _tycoonCard03Componet;
|
|
|
|
void Start()
|
|
{
|
|
mainCamera = TycoonCameraManager.Instance.MainCamera;
|
|
}
|
|
|
|
[Button("카드 생성하기(레벨업)")]
|
|
private void CreateCard()
|
|
{
|
|
if (!Application.isPlaying) return;
|
|
|
|
// 기존 카드가 있으면 삭제
|
|
if (_currentCard01 != null)
|
|
{
|
|
Destroy(_currentCard01);
|
|
}
|
|
if (_currentCard02 != null)
|
|
{
|
|
Destroy(_currentCard02);
|
|
}
|
|
if (_currentCard03 != null)
|
|
{
|
|
Destroy(_currentCard03);
|
|
}
|
|
|
|
_currentCard01 = Instantiate(card01, this.transform);
|
|
_currentCard01.name = "Card";
|
|
|
|
_currentCard02 = Instantiate(card02, this.transform);
|
|
_currentCard02.name = "Card02";
|
|
|
|
_currentCard03 = Instantiate(card03, this.transform);
|
|
_currentCard03.name = "Card03";
|
|
|
|
_currentCard01.transform.localPosition = new Vector3(-550, 0, 0);
|
|
_currentCard02.transform.localPosition = new Vector3(0, 0, 0);
|
|
_currentCard03.transform.localPosition = new Vector3(550, 0, 0);
|
|
|
|
_tycoonCard01Componet = _currentCard01.GetComponent<TycoonCard>();
|
|
_tycoonCard02Componet = _currentCard02.GetComponent<TycoonCard>();
|
|
_tycoonCard03Componet = _currentCard03.GetComponent<TycoonCard>();
|
|
|
|
|
|
//----카드 값 지정 및 초기화----
|
|
|
|
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);
|
|
|
|
//-------------
|
|
|
|
_tycoonCard01Componet.Rotation_Start();
|
|
_tycoonCard02Componet.Rotation_Start();
|
|
_tycoonCard03Componet.Rotation_Start();
|
|
}
|
|
|
|
public void SelectedCard(TycoonCard currTycoonCard)
|
|
{
|
|
SelectedAnimation(currTycoonCard);
|
|
}
|
|
|
|
private IEnumerator SelectedAnimation(TycoonCard currTycoonCard)
|
|
{
|
|
|
|
// 화면의 해상도를 가져옴
|
|
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;
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|