206 lines
6.8 KiB
C#
206 lines
6.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using BlueWater.Tycoons;
|
|
using BlueWater.Utility;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.Localization;
|
|
using UnityEngine.Localization.Settings;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class TycoonCard : MonoBehaviour
|
|
{
|
|
[field: Title("컴포넌트")]
|
|
[field: SerializeField]
|
|
public RectTransform RectTransform { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public Transform Panel { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public Image CardImage { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public GameObject BackObject { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public GameObject PriceUi { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public TMP_Text PriceText { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public TycoonCardArea CardArea { get; private set; }
|
|
|
|
[Title("카드 속성")]
|
|
[SerializeField]
|
|
private TMP_Text _informationText;
|
|
|
|
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 bool _isPointerInside; // 이미지 안에 마우스가 있는지 여부를 추적
|
|
private Coroutine _startRotationCoroutine;
|
|
private Coroutine _endRotationCoroutine;
|
|
|
|
private Coroutine _changedLocaleInstance;
|
|
|
|
private void Start()
|
|
{
|
|
LocalizationSettings.SelectedLocaleChanged += OnChangedLocale;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
LocalizationSettings.SelectedLocaleChanged -= OnChangedLocale;
|
|
}
|
|
|
|
private void OnChangedLocale(Locale locale)
|
|
{
|
|
Utils.StartUniqueCoroutine(this, ref _changedLocaleInstance, ChangeLocaleCoroutine(locale));
|
|
StartCoroutine(ChangeLocaleCoroutine(locale));
|
|
}
|
|
|
|
private IEnumerator ChangeLocaleCoroutine(Locale locale)
|
|
{
|
|
var loadingOperation = Utils.GetTableAsync();
|
|
yield return loadingOperation;
|
|
|
|
if (loadingOperation.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
var table = loadingOperation.Result;
|
|
var textValue = table.GetEntry(CardDataForIdx.Idx)?.GetLocalizedString();
|
|
_informationText.text = textValue;
|
|
}
|
|
}
|
|
|
|
public void SetName(string objectName) => gameObject.name = objectName;
|
|
public void SetLocalPosition(Vector3 localPosition) => transform.localPosition = localPosition;
|
|
public void SetLocalScale(Vector3 localScale) => transform.localScale = localScale;
|
|
|
|
//지정된 IDX값으로 정보값 초기화
|
|
public void SetCard(CardData cardData)
|
|
{
|
|
CardDataForIdx = cardData;
|
|
_informationText.text = Utils.GetLocalizedString(cardData.Idx);
|
|
CardImage.sprite = CardDataForIdx.Sprite;
|
|
}
|
|
|
|
public void SetSelectAction(Action<TycoonCard> action)
|
|
{
|
|
CardArea.SetselectAction(action);
|
|
}
|
|
|
|
public void SetPrice(int price)
|
|
{
|
|
PriceText.text = price.ToString("N0");
|
|
PriceUi.SetActive(true);
|
|
}
|
|
|
|
[Button("회전")]
|
|
public void Rotation_Start()
|
|
{
|
|
Panel.localRotation = Quaternion.Euler(0, -180, 0);
|
|
Panel.localScale = new Vector3(0, 0, 0);
|
|
|
|
if (_currentRotationCoroutine != null)
|
|
{
|
|
StopCoroutine(_currentRotationCoroutine);
|
|
_currentRotationCoroutine = null;
|
|
}
|
|
|
|
_currentRotationCoroutine = StartCoroutine(RotateOverTime());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카드를 등장하며 회전시킴!
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private IEnumerator RotateOverTime()
|
|
{
|
|
BackObject.SetActive(true);
|
|
Quaternion startRotation = Panel.localRotation;
|
|
Quaternion targetRotation = Quaternion.Euler(0, 0, 0);
|
|
|
|
Vector3 initialScale = Panel.localScale;
|
|
|
|
float elapsedTime = 0.0f;
|
|
|
|
while (elapsedTime < 0.5f)
|
|
{
|
|
elapsedTime += Time.unscaledDeltaTime;
|
|
|
|
float t = elapsedTime / 0.5f;
|
|
float easedT = EaseEffect.BounceOut(t);
|
|
|
|
Panel.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);
|
|
|
|
Panel.localRotation = Quaternion.Lerp(startRotation, targetRotation, easedT);
|
|
|
|
float currentYRotation = Panel.localRotation.eulerAngles.y;
|
|
|
|
if (currentYRotation <= 90.0f && BackObject.activeSelf)
|
|
{
|
|
BackObject.SetActive(false);
|
|
}
|
|
|
|
if (elapsedTime > rotationDurationCard / 1.8)
|
|
{
|
|
CardArea.SetEnable(true);
|
|
}
|
|
|
|
yield return null;
|
|
}
|
|
|
|
Panel.localRotation = targetRotation;
|
|
}
|
|
}
|
|
} |