2024-09-12 04:17:34 +00:00
|
|
|
using System;
|
2024-09-09 09:50:37 +00:00
|
|
|
using System.Collections;
|
|
|
|
using BlueWater.Tycoons;
|
2024-11-11 02:02:24 +00:00
|
|
|
using BlueWater.Utility;
|
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;
|
2024-11-11 02:02:24 +00:00
|
|
|
using UnityEngine.Localization;
|
|
|
|
using UnityEngine.Localization.Settings;
|
|
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
2024-10-03 07:55:56 +00:00
|
|
|
using UnityEngine.Serialization;
|
2024-09-12 04:17:34 +00:00
|
|
|
using UnityEngine.UI;
|
2024-09-24 10:09:17 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
namespace BlueWater.Uis
|
|
|
|
{
|
|
|
|
public class TycoonCard : MonoBehaviour
|
2024-11-12 09:33:07 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
[field: Title("컴포넌트")]
|
|
|
|
[field: SerializeField]
|
|
|
|
public RectTransform RectTransform { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public Transform Panel { get; private set; }
|
2024-10-03 07:55:56 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public Image CardImage { get; private set; }
|
2024-10-03 07:55:56 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
[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; }
|
2024-11-11 02:02:24 +00:00
|
|
|
|
2024-11-26 08:18:41 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public GameObject _countLayout;
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
private Sprite _cardCountEnabled;
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
private Sprite _cardCountDisabled;
|
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
[Title("카드 속성")]
|
|
|
|
[SerializeField]
|
|
|
|
private TMP_Text _informationText;
|
2024-11-11 02:02:24 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
internal CardData CardDataForIdx;
|
|
|
|
//[field: SerializeField, CLabel("IDX"), ReadOnly]
|
|
|
|
//private string _cardData = "AddAllLiquid";
|
|
|
|
|
2024-11-18 04:08:32 +00:00
|
|
|
[field: SerializeField]
|
2024-11-17 04:29:57 +00:00
|
|
|
private string cardName;
|
|
|
|
|
|
|
|
//[field: SerializeField, CLabel("카드 이미지")]
|
|
|
|
//private Image CardImage;
|
2024-11-18 04:08:32 +00:00
|
|
|
[field: SerializeField]
|
2024-11-17 04:29:57 +00:00
|
|
|
private string cardText;
|
2024-11-11 02:02:24 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
private Coroutine _currentRotationCoroutine;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("RotationDurationCard")]
|
|
|
|
[field: Title("카드 회전")]
|
2024-11-18 04:08:32 +00:00
|
|
|
[field: SerializeField]
|
2024-11-17 04:29:57 +00:00
|
|
|
internal float rotationDurationCard = 1.0f;
|
|
|
|
|
2024-11-18 04:08:32 +00:00
|
|
|
[field: SerializeField]
|
2024-11-17 04:29:57 +00:00
|
|
|
public Acceleration accelerationCard;
|
|
|
|
|
|
|
|
[field: Title("부가효과 : 카드 기울기")]
|
2024-11-18 04:08:32 +00:00
|
|
|
[field: SerializeField]
|
2024-11-17 04:29:57 +00:00
|
|
|
internal float maxRotationAngle = 15f;
|
|
|
|
|
2024-11-18 04:08:32 +00:00
|
|
|
[field: SerializeField]
|
2024-11-17 04:29:57 +00:00
|
|
|
internal float returnSpeed = 1.0f;
|
|
|
|
|
2024-11-28 23:07:50 +00:00
|
|
|
public int CardPrice { get; private set; }
|
2024-11-17 04:29:57 +00:00
|
|
|
private bool _isPointerInside; // 이미지 안에 마우스가 있는지 여부를 추적
|
|
|
|
private Coroutine _startRotationCoroutine;
|
|
|
|
private Coroutine _endRotationCoroutine;
|
|
|
|
|
|
|
|
private Coroutine _changedLocaleInstance;
|
|
|
|
|
2024-11-19 13:32:43 +00:00
|
|
|
private void OnEnable()
|
2024-11-11 02:02:24 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
LocalizationSettings.SelectedLocaleChanged += OnChangedLocale;
|
2024-11-11 02:02:24 +00:00
|
|
|
}
|
|
|
|
|
2024-11-19 13:32:43 +00:00
|
|
|
private void OnDisable()
|
2024-09-12 04:17:34 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
LocalizationSettings.SelectedLocaleChanged -= OnChangedLocale;
|
2024-09-12 04:17:34 +00:00
|
|
|
}
|
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
private void OnChangedLocale(Locale locale)
|
|
|
|
{
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _changedLocaleInstance, ChangeLocaleCoroutine(locale));
|
|
|
|
StartCoroutine(ChangeLocaleCoroutine(locale));
|
|
|
|
}
|
2024-09-09 09:50:37 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
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;
|
2024-09-09 09:50:37 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
//지정된 IDX값으로 정보값 초기화
|
|
|
|
public void SetCard(CardData cardData)
|
2024-10-03 07:55:56 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
CardDataForIdx = cardData;
|
2024-11-28 23:07:50 +00:00
|
|
|
int count = TycoonManager.Instance.TycoonCardController.GetSelectedCardCount(CardDataForIdx.Idx);
|
2024-11-26 08:18:41 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
_informationText.text = Utils.GetLocalizedString(cardData.Idx);
|
2024-11-26 08:18:41 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
CardImage.sprite = CardDataForIdx.Sprite;
|
2024-11-26 08:18:41 +00:00
|
|
|
for(int i = 0 ; i < CardDataForIdx.Max ; i ++)
|
|
|
|
{
|
|
|
|
GameObject childObject = new GameObject(i.ToString());
|
|
|
|
Image image = childObject.AddComponent<Image>();
|
|
|
|
|
|
|
|
if (i < count)
|
|
|
|
{
|
|
|
|
image.sprite = _cardCountEnabled;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
image.sprite = _cardCountDisabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
childObject.transform.SetParent(_countLayout.transform);
|
|
|
|
RectTransform rectTransform = childObject.GetComponent<RectTransform>();
|
|
|
|
rectTransform.sizeDelta = new Vector2(30, 30);
|
|
|
|
rectTransform.localScale = new Vector3(1.0f,1.0f,1.0f);
|
|
|
|
rectTransform.localRotation = new Quaternion(0.0f,0.0f,0.0f,0.0f);
|
|
|
|
rectTransform.localPosition = new Vector3(0.0f,0.0f,0.0f);
|
|
|
|
}
|
2024-10-03 07:55:56 +00:00
|
|
|
}
|
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
public void SetSelectAction(Action<TycoonCard> action)
|
|
|
|
{
|
|
|
|
CardArea.SetselectAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetPrice(int price)
|
|
|
|
{
|
2024-11-28 23:07:50 +00:00
|
|
|
CardPrice = price;
|
|
|
|
PriceText.text = CardPrice.ToString("N0");
|
2024-11-17 04:29:57 +00:00
|
|
|
PriceUi.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Button("회전")]
|
|
|
|
public void Rotation_Start()
|
2024-09-09 09:50:37 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
Panel.localRotation = Quaternion.Euler(0, -180, 0);
|
|
|
|
Panel.localScale = new Vector3(0, 0, 0);
|
2024-09-09 09:50:37 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
if (_currentRotationCoroutine != null)
|
|
|
|
{
|
|
|
|
StopCoroutine(_currentRotationCoroutine);
|
|
|
|
_currentRotationCoroutine = null;
|
|
|
|
}
|
2024-09-12 04:17:34 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
_currentRotationCoroutine = StartCoroutine(RotateOverTime());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 카드를 등장하며 회전시킴!
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
|
|
|
private IEnumerator RotateOverTime()
|
|
|
|
{
|
|
|
|
BackObject.SetActive(true);
|
2024-11-26 08:18:41 +00:00
|
|
|
_countLayout.SetActive(false);
|
2024-11-17 04:29:57 +00:00
|
|
|
Quaternion startRotation = Panel.localRotation;
|
|
|
|
Quaternion targetRotation = Quaternion.Euler(0, 0, 0);
|
2024-09-09 09:50:37 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
Vector3 initialScale = Panel.localScale;
|
2024-09-09 09:50:37 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
float elapsedTime = 0.0f;
|
2024-09-12 04:17:34 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
while (elapsedTime < 0.5f)
|
2024-09-09 09:50:37 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
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;
|
2024-09-09 09:50:37 +00:00
|
|
|
}
|
2024-10-03 07:55:56 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
elapsedTime = 0.0f;
|
|
|
|
|
|
|
|
while (elapsedTime < rotationDurationCard)
|
2024-10-03 07:55:56 +00:00
|
|
|
{
|
2024-11-17 04:29:57 +00:00
|
|
|
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);
|
2024-11-26 08:18:41 +00:00
|
|
|
_countLayout.SetActive(true);
|
2024-11-17 04:29:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (elapsedTime > rotationDurationCard / 1.8)
|
|
|
|
{
|
|
|
|
CardArea.SetEnable(true);
|
|
|
|
}
|
2024-11-26 08:18:41 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
yield return null;
|
2024-10-03 07:55:56 +00:00
|
|
|
}
|
2024-09-09 09:50:37 +00:00
|
|
|
|
2024-11-17 04:29:57 +00:00
|
|
|
Panel.localRotation = targetRotation;
|
|
|
|
}
|
2024-11-26 08:18:41 +00:00
|
|
|
|
|
|
|
public void CardCountUp()
|
|
|
|
{
|
|
|
|
if (CardDataForIdx.Max != 0)
|
|
|
|
{
|
2024-11-28 23:07:50 +00:00
|
|
|
int count = TycoonManager.Instance.TycoonCardController.GetSelectedCardCount(CardDataForIdx.Idx);
|
2024-11-26 08:18:41 +00:00
|
|
|
|
|
|
|
var image = _countLayout.transform.Find(count.ToString());
|
|
|
|
image.GetComponent<Image>().sprite = _cardCountEnabled;
|
|
|
|
}
|
|
|
|
}
|
2024-09-09 09:50:37 +00:00
|
|
|
}
|
|
|
|
}
|