CapersProject/Assets/02.Scripts/Ui/Tycoon/TycoonCard.cs
2024-10-28 18:09:18 +09:00

191 lines
6.2 KiB
C#

using System;
using System.Collections;
using BlueWater;
using BlueWater.Tycoons;
using BlueWater.Uis;
using Sirenix.OdinInspector;
using UnityEngine;
using TMPro;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;
using Object = UnityEngine.Object;
public class TycoonCard : MonoBehaviour
{
private TycoonSelectCard _selectCardUi;
[field: Title("카드 속성")]
internal CardData CardDataForIdx;
[field: SerializeField, CLabel("IDX"), ReadOnly]
private string _cardData = "AddAllLiquid";
[field: SerializeField, CLabel("카드 이름")]
private string cardName;
//[field: SerializeField, CLabel("카드 이미지")]
//private Image CardImage;
[field: SerializeField, CLabel("카드 텍스트")]
private string cardText;
private Coroutine _currentRotationCoroutine;
[FormerlySerializedAs("RotationDurationCard")]
[field: Title("카드 회전")]
[field: SerializeField, CLabel("카드 회전 속도")]
internal float rotationDurationCard = 1.0f;
[field: SerializeField, CLabel("회전 가속 종류")]
public Acceleration accelerationCard;
[field: Title("부가효과 : 카드 기울기")]
[field: SerializeField, CLabel("최대 기울기(각도)")]
internal float maxRotationAngle = 15f;
[field: SerializeField, CLabel("기울기 복원 속도")]
internal float returnSpeed = 1.0f;
private float _returnSpeedTime = 0.0f; // 복원속도를 더할 메서드
private bool _isPointerInside; // 이미지 안에 마우스가 있는지 여부를 추적
private Coroutine _startRotationCoroutine;
private Coroutine _endRotationCoroutine;
private Image _image;
private RectTransform _rectTransform;
private Transform _cardComTransform;
private TycoonCardArea _cardArea;
private void Awake()
{
_rectTransform = GetComponent<RectTransform>();
_cardComTransform = transform.Find("CardCom").GetComponent<Transform>();
_image = _cardComTransform.Find("Image").GetComponent<Image>();
_selectCardUi = transform.GetComponentInParent<TycoonSelectCard>();
_cardArea = transform.Find("Area").GetComponent<TycoonCardArea>();
}
void Start()
{
}
private void Update()
{
//Debug.Log(_mainCamera.WorldToScreenPoint(GameManager.Instance.CurrentTycoonPlayer.transform.position));
//카메라 기준 캐릭터의 위치를 가져옴
}
//지정된 IDX값으로 정보값 초기화
public void SetCard(string cardIdx)
{
CardDataForIdx = TycoonManager.Instance.CardDataSo.GetDataByIdx(cardIdx);
Transform infoTransform = transform.Find("CardCom/Infomation");
TextMeshProUGUI infotextComponent = infoTransform.GetComponent<TextMeshProUGUI>();
infotextComponent.text = CardDataForIdx.ScriptText;
_image.sprite = CardDataForIdx.Sprite;
}
[Button("회전")]
public void Rotation_Start()
{
_cardComTransform.localRotation = Quaternion.Euler(0, -180,0);
_cardComTransform.localScale = new Vector3(0,0,0);
if (_currentRotationCoroutine != null)
{
StopCoroutine(_currentRotationCoroutine);
_currentRotationCoroutine = null;
}
_currentRotationCoroutine = StartCoroutine(RotateOverTime());
// Resources.Load()
}
public void Spawn()
{
}
/*
*
// 마우스 클릭 시 호출
public void OnPointerClick(PointerEventData eventData)
{
if (_enable)
{
switch (_cardData) //탐색 후 행동...
{
//TycoonManager.Instance.TycoonStatus.CurrentExp += 10; 이런거 넣어주자...
case "": break;
default:
Debug.Log("Not Found Card : IDX");
break;
}
TycoonManager.Instance.CardDataSo.AddToSelectedCard(_cardDataForIdx);
//해당 밑줄은 따로 메소드를 만들어주자... 여기서 호출하는게 아니라 SelectCardUi에서 호출받는 방식으로...
this.SetEnable(false);
_isPointerInside = false;
}
}
*/
private IEnumerator RotateOverTime() //카드를 등장하며 회전시킴!
{
Transform backObject = transform.Find("CardCom/Back");
backObject.gameObject.SetActive(true);
Quaternion startRotation = _cardComTransform.localRotation;
Quaternion targetRotation = Quaternion.Euler(0, 0, 0);
Vector3 initialScale = _cardComTransform.localScale;
float elapsedTime = 0.0f;
while (elapsedTime < 0.5f)
{
elapsedTime += Time.unscaledDeltaTime;
float t = elapsedTime / 0.5f;
float easedT = EaseEffect.BounceOut(t);
_cardComTransform.localScale = Vector3.Lerp(initialScale, new Vector3(0.95f,0.95f,0.95f), easedT);
yield return null;
}
elapsedTime = 0.0f;
while (elapsedTime < rotationDurationCard)
{
elapsedTime += Time.unscaledDeltaTime;
float t = elapsedTime / rotationDurationCard;
float easedT = t;
if (accelerationCard == Acceleration.EaseExpoIn) easedT = Mathf.Pow(2, 10 * (t - 1)) ;
else if (accelerationCard == Acceleration.EaseExpoOut) easedT = 1 - Mathf.Pow(2, -10 * t);
else if (accelerationCard == Acceleration.EaseBounceIn) easedT = 1 - EaseEffect.BounceOut(1 - t);
else if (accelerationCard == Acceleration.EaseBounceOut) easedT = EaseEffect.BounceOut(t);
_cardComTransform.localRotation = Quaternion.Lerp(startRotation, targetRotation, easedT);
float currentYRotation = _cardComTransform.localRotation.eulerAngles.y;
if (currentYRotation <= 90.0f && backObject.gameObject.activeSelf)
{
backObject.gameObject.SetActive(false);
}
if (elapsedTime > rotationDurationCard / 1.8)
{
_cardArea.SetEnable(true);
}
yield return null;
}
_cardComTransform.localRotation = targetRotation;
}
}