173 lines
5.0 KiB
C#
173 lines
5.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using BlueWater;
|
|
using BlueWater.Tycoons;
|
|
using SingularityGroup.HotReload;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using Object = UnityEngine.Object; // TextMeshPro 네임스페이스 추가
|
|
|
|
|
|
public enum Acceleration
|
|
{
|
|
|
|
None = default,
|
|
EaseExpoIn,
|
|
EaseExpoOut,
|
|
EaseBounceIn,
|
|
EaseBounceOut,
|
|
|
|
// EaseBounceOut = None
|
|
//아직 정해지지 않은건 None표시
|
|
}
|
|
|
|
public class TycoonCard : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
|
{
|
|
|
|
|
|
|
|
[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()
|
|
{
|
|
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()
|
|
}
|
|
|
|
|
|
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()
|
|
{
|
|
RectTransform rectTransform = this.GetComponent<RectTransform>();
|
|
Transform backObject = rectTransform.Find("Back");
|
|
backObject.gameObject.SetActive(true);
|
|
Quaternion startRotation = rectTransform.localRotation;
|
|
Quaternion targetRotation = Quaternion.Euler(0, 0, 0);
|
|
|
|
float elapsedTime = 0f;
|
|
|
|
while (elapsedTime < RotationDurationCard)
|
|
{
|
|
elapsedTime += Time.deltaTime;
|
|
|
|
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);
|
|
|
|
rectTransform.localRotation = Quaternion.Lerp(startRotation, targetRotation, easedT);
|
|
|
|
float currentYRotation = rectTransform.localRotation.eulerAngles.y;
|
|
|
|
if (currentYRotation <= 90.0f && backObject.gameObject.activeSelf)
|
|
{
|
|
backObject.gameObject.SetActive(false);
|
|
}
|
|
|
|
yield return null;
|
|
}
|
|
|
|
rectTransform.localRotation = targetRotation;
|
|
}
|
|
|
|
|
|
|
|
//가속도를 위한 함수...▼
|
|
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;
|
|
}
|
|
}
|
|
} |