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

173 lines
5.0 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-12 04:17:34 +00:00
using SingularityGroup.HotReload;
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;
using UnityEngine.UI;
using Object = UnityEngine.Object; // TextMeshPro 네임스페이스 추가
2024-09-09 09:50:37 +00:00
2024-09-12 04:17:34 +00:00
public enum Acceleration
{
None = default,
EaseExpoIn,
EaseExpoOut,
EaseBounceIn,
EaseBounceOut,
// EaseBounceOut = None
//아직 정해지지 않은건 None표시
}
public class TycoonCard : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
2024-09-09 09:50:37 +00:00
{
2024-09-12 04:17:34 +00:00
[field: Title("카드 속성")]
private CardData _cardData_IDX;
[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;
[field: Title("카드 회전")]
[field: SerializeField, CLabel("카드 회전 속도")]
private float RotationDurationCard = 1.0f;
[field: SerializeField, CLabel("회전 가속 종류")]
public Acceleration AccelerationCard;
[Button("회전")]
public void Rotation_Start()
2024-09-09 09:50:37 +00:00
{
2024-09-12 04:17:34 +00:00
RectTransform rectTransform = this.GetComponent<RectTransform>();
rectTransform.localRotation = Quaternion.Euler(0,-180,0);
if (currentRotationCoroutine != null)
{
StopCoroutine(currentRotationCoroutine);
currentRotationCoroutine = null;
}
currentRotationCoroutine = StartCoroutine(RotateOverTime());
var a = TycoonManager.Instance.GetCardDataByIdx(_cardData);
// Resources.Load()
2024-09-09 09:50:37 +00:00
}
2024-09-12 04:17:34 +00:00
void Start()
{
_cardData_IDX = TycoonManager.Instance.GetCardDataByIdx(_cardData);
Transform nameTransform = transform.Find("Name");
Transform infoTransform = transform.Find("Infomation");
TextMeshProUGUI nametextComponent = nameTransform.GetComponent<TextMeshProUGUI>();
nametextComponent.text = _cardData_IDX.Img;
TextMeshProUGUI infotextComponent = infoTransform.GetComponent<TextMeshProUGUI>();
infotextComponent.text = _cardData_IDX.ScriptText;
}
// 마우스가 이미지 위에 올라갔을 때 호출
public void OnPointerEnter(PointerEventData eventData)
{
Debug.Log("OnMouse");
}
// 마우스가 이미지에서 벗어났을 때 호출
public void OnPointerExit(PointerEventData eventData)
{
Debug.Log("OffMouse");
//image.color = originalColor; // 원래 색상으로 복원
}
// 마우스 클릭 시 호출
public void OnPointerClick(PointerEventData eventData)
{
Debug.Log("ClickMouse");
// image.color = clickColor; // 클릭 시 색상을 변경
}
private IEnumerator RotateOverTime()
2024-09-09 09:50:37 +00:00
{
RectTransform rectTransform = this.GetComponent<RectTransform>();
Transform backObject = rectTransform.Find("Back");
2024-09-12 04:17:34 +00:00
backObject.gameObject.SetActive(true);
2024-09-09 09:50:37 +00:00
Quaternion startRotation = rectTransform.localRotation;
2024-09-12 04:17:34 +00:00
Quaternion targetRotation = Quaternion.Euler(0, 0, 0);
2024-09-09 09:50:37 +00:00
float elapsedTime = 0f;
2024-09-12 04:17:34 +00:00
while (elapsedTime < RotationDurationCard)
2024-09-09 09:50:37 +00:00
{
elapsedTime += Time.deltaTime;
2024-09-12 04:17:34 +00:00
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 - BounceOut(1 - t);
else if (AccelerationCard == Acceleration.EaseBounceOut) easedT = BounceOut(t);
2024-09-09 09:50:37 +00:00
rectTransform.localRotation = Quaternion.Lerp(startRotation, targetRotation, easedT);
float currentYRotation = rectTransform.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-09-12 04:17:34 +00:00
2024-09-09 09:50:37 +00:00
yield return null;
}
rectTransform.localRotation = targetRotation;
}
2024-09-12 04:17:34 +00:00
//가속도를 위한 함수...▼
float BounceOut(float t)
{
if (t < (1 / 2.75f))
{
return 7.5625f * t * t;
}
else if (t < (2 / 2.75f))
{
t -= (1.5f / 2.75f);
return 7.5625f * t * t + 0.75f;
}
else if (t < (2.5f / 2.75f))
{
t -= (2.25f / 2.75f);
return 7.5625f * t * t + 0.9375f;
}
else
{
t -= (2.625f / 2.75f);
return 7.5625f * t * t + 0.984375f;
}
}
2024-09-09 09:50:37 +00:00
}