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

177 lines
5.2 KiB
C#
Raw Normal View History

2024-09-10 10:25:05 +00:00
using BlueWater.Interfaces;
using BlueWater.Items;
using BlueWater.Tycoons;
using DG.Tweening;
using Sirenix.OdinInspector;
2024-10-28 04:52:11 +00:00
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
namespace BlueWater.Uis
{
2024-09-10 10:25:05 +00:00
public class BalloonUi : MonoBehaviour
{
2024-09-10 10:25:05 +00:00
[Title("컴포넌트")]
[SerializeField, Required]
private Image _fillImage;
2024-09-10 10:25:05 +00:00
[SerializeField, Required]
private Image _itemImage;
[SerializeField]
private GameObject _panel;
[Title("주문 정보")]
[SerializeField, DisableIf("@true")]
private bool _isOrdered;
[SerializeField, DisableIf("@true")]
private bool _isWaitTimeOver;
[SerializeField, DisableIf("@true")]
2024-09-10 10:25:05 +00:00
private bool _isItemReceived;
2024-11-19 06:03:43 +00:00
private Tween _fillTween;
private Tween _colorTween;
2024-09-30 12:05:19 +00:00
private CocktailData _orderCocktailData;
private void Awake()
{
InitializeComponents();
}
[Button("컴포넌트 초기화")]
private void InitializeComponents()
{
2024-09-10 10:25:05 +00:00
_fillImage = transform.Find("Panel/FillImage").GetComponent<Image>();
_itemImage = transform.Find("Panel/FoodImage").GetComponent<Image>();
_panel = transform.Find("Panel").gameObject;
}
2024-09-10 10:25:05 +00:00
public void ShowUi() => _panel.SetActive(true);
public void HideUi() => _panel.SetActive(false);
2024-09-10 10:25:05 +00:00
public void SetItemImage(IPickup item)
{
2024-09-10 10:25:05 +00:00
if (!item.Sprite)
{
2024-09-10 10:25:05 +00:00
Debug.LogWarning($"{item.Sprite} 해당 음식의 이미지가 없습니다.");
}
2024-10-27 09:44:22 +00:00
2024-09-10 10:25:05 +00:00
SetItemSprite(item.Sprite);
ShowUi();
}
2024-09-23 02:00:21 +00:00
2024-10-14 11:13:08 +00:00
public void ResetUi()
{
_isOrdered = false;
_isWaitTimeOver = false;
_isItemReceived = false;
}
2024-09-23 02:00:21 +00:00
public void SetEmpty()
{
SetItemSprite(null);
}
2024-09-10 10:25:05 +00:00
public void SetItemSprite(Sprite sprite)
{
_itemImage.sprite = sprite;
}
public void DiscardItem()
{
2024-10-06 23:41:09 +00:00
HideUi();
SetEmpty();
}
2024-11-19 06:03:43 +00:00
public void OrderItem(string itemIdx, float waitTime, float hurryTime, bool isReverse = false, Color? startColor = null, Color? endColor = null)
{
2024-09-30 12:05:19 +00:00
_orderCocktailData = ItemManager.Instance.CocktailDataSo.GetDataByIdx(itemIdx);
_isOrdered = true;
_isWaitTimeOver = false;
2024-09-10 10:25:05 +00:00
_isItemReceived = false;
2024-09-30 12:05:19 +00:00
SetItemImage(_orderCocktailData);
2024-10-06 23:41:09 +00:00
2024-11-19 06:03:43 +00:00
SetTween(waitTime, hurryTime, isReverse, startColor, endColor);
2024-10-06 23:41:09 +00:00
}
2024-11-19 06:03:43 +00:00
public void OrderItem(Sprite sprite, float waitTime, float hurryTime, bool isReverse = false, Color? startColor = null, Color? endColor = null)
2024-10-06 23:41:09 +00:00
{
_isOrdered = true;
_isWaitTimeOver = false;
_isItemReceived = false;
SetItemSprite(sprite);
ShowUi();
2024-10-15 18:01:16 +00:00
2024-11-19 06:03:43 +00:00
SetTween(waitTime, hurryTime, isReverse, startColor, endColor);
2024-10-15 18:01:16 +00:00
}
2024-11-19 06:03:43 +00:00
public void SetTween(float waitTime, float hurryTime, bool isReverse = false, Color? startColor = null, Color? endColor = null)
2024-10-15 18:01:16 +00:00
{
2024-11-19 06:03:43 +00:00
float startValue = isReverse ? 1f : 0f;
float endValue = isReverse ? 0f : 1f;
2024-11-19 07:57:05 +00:00
_fillTween?.Kill();
2024-11-19 06:03:43 +00:00
_fillTween = _fillImage.DOFillAmount(endValue, hurryTime)
.From(startValue)
.SetEase(Ease.Linear)
.SetDelay(waitTime)
.OnComplete(OnTweenComplete)
2024-11-19 06:03:43 +00:00
.SetAutoKill(true);
if (startColor != null && endColor != null)
{
2024-11-19 07:57:05 +00:00
_colorTween?.Kill();
2024-11-19 06:03:43 +00:00
_colorTween = _fillImage.DOColor((Color)endColor, hurryTime)
.From((Color)startColor)
.SetEase(Ease.Linear)
.SetDelay(waitTime)
.SetAutoKill(true);
}
}
2024-10-28 04:52:11 +00:00
public void ResetGauge()
{
2024-11-19 06:03:43 +00:00
if (_fillTween == null)
2024-10-28 04:52:11 +00:00
{
2024-10-31 05:41:13 +00:00
Debug.LogError("BalloonUi 게이지 리셋 오류");
2024-10-28 04:52:11 +00:00
return;
}
2024-11-19 06:03:43 +00:00
_fillTween.Restart();
2024-10-28 04:52:11 +00:00
}
public void PayMoney(int waitTime, int hurryTime)
{
_isOrdered = true;
_isWaitTimeOver = false;
2024-09-10 10:25:05 +00:00
_isItemReceived = false;
2024-11-12 09:15:42 +00:00
SetItemSprite(DataManager.Instance.SpriteDataSo.Gold01);
ShowUi();
2024-11-19 06:03:43 +00:00
_fillTween = _fillImage.DOFillAmount(1f, hurryTime)
.From(0f)
.SetEase(Ease.Linear)
.SetDelay(waitTime)
.OnComplete(OnTweenComplete)
.SetAutoKill(false);
}
private void OnTweenComplete()
{
_isWaitTimeOver = true;
HideUi();
}
public bool IsWaitTimeOver() => _isOrdered && _isWaitTimeOver;
2024-09-10 10:25:05 +00:00
public bool IsFoodReceive() => _isItemReceived;
2024-10-06 23:41:09 +00:00
public void ReceiveItem(IPickup pickupItem)
{
2024-11-19 06:03:43 +00:00
_fillTween.Kill();
HideUi();
2024-09-10 10:25:05 +00:00
_isItemReceived = true;
}
}
}