177 lines
5.2 KiB
C#
177 lines
5.2 KiB
C#
using BlueWater.Interfaces;
|
|
using BlueWater.Items;
|
|
using BlueWater.Tycoons;
|
|
using DG.Tweening;
|
|
using Sirenix.OdinInspector;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class BalloonUi : MonoBehaviour
|
|
{
|
|
[Title("컴포넌트")]
|
|
[SerializeField, Required]
|
|
private Image _fillImage;
|
|
|
|
[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")]
|
|
private bool _isItemReceived;
|
|
|
|
private Tween _fillTween;
|
|
private Tween _colorTween;
|
|
private CocktailData _orderCocktailData;
|
|
|
|
private void Awake()
|
|
{
|
|
InitializeComponents();
|
|
}
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
private void InitializeComponents()
|
|
{
|
|
_fillImage = transform.Find("Panel/FillImage").GetComponent<Image>();
|
|
_itemImage = transform.Find("Panel/FoodImage").GetComponent<Image>();
|
|
_panel = transform.Find("Panel").gameObject;
|
|
}
|
|
|
|
public void ShowUi() => _panel.SetActive(true);
|
|
public void HideUi() => _panel.SetActive(false);
|
|
|
|
public void SetItemImage(IPickup item)
|
|
{
|
|
if (!item.Sprite)
|
|
{
|
|
Debug.LogWarning($"{item.Sprite} 해당 음식의 이미지가 없습니다.");
|
|
}
|
|
|
|
SetItemSprite(item.Sprite);
|
|
ShowUi();
|
|
}
|
|
|
|
public void ResetUi()
|
|
{
|
|
_isOrdered = false;
|
|
_isWaitTimeOver = false;
|
|
_isItemReceived = false;
|
|
}
|
|
|
|
public void SetEmpty()
|
|
{
|
|
SetItemSprite(null);
|
|
}
|
|
|
|
public void SetItemSprite(Sprite sprite)
|
|
{
|
|
_itemImage.sprite = sprite;
|
|
}
|
|
|
|
public void DiscardItem()
|
|
{
|
|
HideUi();
|
|
SetEmpty();
|
|
}
|
|
|
|
public void OrderItem(string itemIdx, float waitTime, float hurryTime, bool isReverse = false, Color? startColor = null, Color? endColor = null)
|
|
{
|
|
_orderCocktailData = ItemManager.Instance.CocktailDataSo.GetDataByIdx(itemIdx);
|
|
_isOrdered = true;
|
|
_isWaitTimeOver = false;
|
|
_isItemReceived = false;
|
|
SetItemImage(_orderCocktailData);
|
|
|
|
SetTween(waitTime, hurryTime, isReverse, startColor, endColor);
|
|
}
|
|
|
|
public void OrderItem(Sprite sprite, float waitTime, float hurryTime, bool isReverse = false, Color? startColor = null, Color? endColor = null)
|
|
{
|
|
_isOrdered = true;
|
|
_isWaitTimeOver = false;
|
|
_isItemReceived = false;
|
|
SetItemSprite(sprite);
|
|
ShowUi();
|
|
|
|
SetTween(waitTime, hurryTime, isReverse, startColor, endColor);
|
|
}
|
|
|
|
public void SetTween(float waitTime, float hurryTime, bool isReverse = false, Color? startColor = null, Color? endColor = null)
|
|
{
|
|
float startValue = isReverse ? 1f : 0f;
|
|
float endValue = isReverse ? 0f : 1f;
|
|
|
|
_fillTween?.Kill();
|
|
_fillTween = _fillImage.DOFillAmount(endValue, hurryTime)
|
|
.From(startValue)
|
|
.SetEase(Ease.Linear)
|
|
.SetDelay(waitTime)
|
|
.OnComplete(OnTweenComplete)
|
|
.SetAutoKill(true);
|
|
|
|
if (startColor != null && endColor != null)
|
|
{
|
|
_colorTween?.Kill();
|
|
_colorTween = _fillImage.DOColor((Color)endColor, hurryTime)
|
|
.From((Color)startColor)
|
|
.SetEase(Ease.Linear)
|
|
.SetDelay(waitTime)
|
|
.SetAutoKill(true);
|
|
}
|
|
}
|
|
|
|
public void ResetGauge()
|
|
{
|
|
if (_fillTween == null)
|
|
{
|
|
Debug.LogError("BalloonUi 게이지 리셋 오류");
|
|
return;
|
|
}
|
|
|
|
_fillTween.Restart();
|
|
}
|
|
|
|
public void PayMoney(int waitTime, int hurryTime)
|
|
{
|
|
_isOrdered = true;
|
|
_isWaitTimeOver = false;
|
|
_isItemReceived = false;
|
|
SetItemSprite(DataManager.Instance.SpriteDataSo.Gold01);
|
|
ShowUi();
|
|
|
|
_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;
|
|
public bool IsFoodReceive() => _isItemReceived;
|
|
|
|
public void ReceiveItem(IPickup pickupItem)
|
|
{
|
|
_fillTween.Kill();
|
|
HideUi();
|
|
_isItemReceived = true;
|
|
}
|
|
}
|
|
} |