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

191 lines
6.2 KiB
C#
Raw Normal View History

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