2024-11-28 23:07:50 +00:00
|
|
|
using System;
|
2024-09-10 10:25:05 +00:00
|
|
|
using BlueWater.Interfaces;
|
2024-06-18 18:16:19 +00:00
|
|
|
using BlueWater.Items;
|
|
|
|
using DG.Tweening;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
2024-07-02 18:27:56 +00:00
|
|
|
namespace BlueWater.Uis
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-09-10 10:25:05 +00:00
|
|
|
public class BalloonUi : MonoBehaviour
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-09-10 10:25:05 +00:00
|
|
|
[Title("컴포넌트")]
|
2024-11-26 08:22:26 +00:00
|
|
|
[SerializeField]
|
|
|
|
private Image _background;
|
|
|
|
|
2024-09-10 10:25:05 +00:00
|
|
|
[SerializeField, Required]
|
|
|
|
private Image _fillImage;
|
2024-11-25 12:36:48 +00:00
|
|
|
|
2024-09-10 10:25:05 +00:00
|
|
|
[SerializeField, Required]
|
|
|
|
private Image _itemImage;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private GameObject _panel;
|
2024-06-18 18:16:19 +00:00
|
|
|
|
2024-11-25 12:36:48 +00:00
|
|
|
[Title("색상 변경 연출")]
|
|
|
|
[SerializeField]
|
|
|
|
private bool _isChangedColor;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Color _startColor = Color.green;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Color _middleColor = Color.yellow;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Color _endColor = Color.red;
|
|
|
|
|
2024-06-18 18:16:19 +00:00
|
|
|
[Title("주문 정보")]
|
|
|
|
[SerializeField, DisableIf("@true")]
|
|
|
|
private bool _isOrdered;
|
|
|
|
|
|
|
|
[SerializeField, DisableIf("@true")]
|
|
|
|
private bool _isWaitTimeOver;
|
2024-11-25 12:36:48 +00:00
|
|
|
|
2024-06-18 18:16:19 +00:00
|
|
|
[SerializeField, DisableIf("@true")]
|
2024-09-10 10:25:05 +00:00
|
|
|
private bool _isItemReceived;
|
2024-11-25 12:36:48 +00:00
|
|
|
|
2024-11-26 08:22:26 +00:00
|
|
|
public CocktailData OrderCocktailData { get; private set; }
|
|
|
|
|
2024-11-19 06:03:43 +00:00
|
|
|
private Tween _fillTween;
|
2024-11-25 12:36:48 +00:00
|
|
|
private Color _previousColor;
|
2024-06-18 18:16:19 +00:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
InitializeComponents();
|
|
|
|
}
|
|
|
|
|
2024-11-28 23:07:50 +00:00
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
_fillTween?.Kill();
|
|
|
|
}
|
|
|
|
|
2024-06-18 18:16:19 +00:00
|
|
|
[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-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
2024-09-10 10:25:05 +00:00
|
|
|
public void ShowUi() => _panel.SetActive(true);
|
|
|
|
public void HideUi() => _panel.SetActive(false);
|
2024-11-25 12:36:48 +00:00
|
|
|
|
2024-09-10 10:25:05 +00:00
|
|
|
public void SetItemImage(IPickup item)
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-09-10 10:25:05 +00:00
|
|
|
if (!item.Sprite)
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-09-10 10:25:05 +00:00
|
|
|
Debug.LogWarning($"{item.Sprite} 해당 음식의 이미지가 없습니다.");
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
2024-11-25 12:36:48 +00:00
|
|
|
|
2024-09-10 10:25:05 +00:00
|
|
|
SetItemSprite(item.Sprite);
|
|
|
|
ShowUi();
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
2024-09-23 02:00:21 +00:00
|
|
|
|
2024-11-26 08:22:26 +00:00
|
|
|
private void ResetUi()
|
2024-10-14 11:13:08 +00:00
|
|
|
{
|
|
|
|
_isOrdered = false;
|
|
|
|
_isWaitTimeOver = false;
|
|
|
|
_isItemReceived = false;
|
|
|
|
}
|
|
|
|
|
2024-11-26 08:22:26 +00:00
|
|
|
private void SetEmpty()
|
2024-09-23 02:00:21 +00:00
|
|
|
{
|
|
|
|
SetItemSprite(null);
|
2024-11-26 08:22:26 +00:00
|
|
|
OrderCocktailData = null;
|
|
|
|
_fillTween?.Kill();
|
2024-09-23 02:00:21 +00:00
|
|
|
}
|
2024-11-25 12:36:48 +00:00
|
|
|
|
2024-09-10 10:25:05 +00:00
|
|
|
public void SetItemSprite(Sprite sprite)
|
|
|
|
{
|
|
|
|
_itemImage.sprite = sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DiscardItem()
|
2024-07-20 11:32:54 +00:00
|
|
|
{
|
2024-10-06 23:41:09 +00:00
|
|
|
HideUi();
|
|
|
|
SetEmpty();
|
2024-11-26 08:22:26 +00:00
|
|
|
ResetUi();
|
2024-10-06 23:41:09 +00:00
|
|
|
}
|
2024-06-18 18:16:19 +00:00
|
|
|
|
2024-11-25 12:36:48 +00:00
|
|
|
public void OrderItem(string itemIdx, float waitTime, float hurryTime, bool isReverse = false)
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-11-26 08:22:26 +00:00
|
|
|
OrderCocktailData = ItemManager.Instance.CocktailDataSo.GetDataByIdx(itemIdx);
|
2024-06-18 18:16:19 +00:00
|
|
|
_isOrdered = true;
|
|
|
|
_isWaitTimeOver = false;
|
2024-09-10 10:25:05 +00:00
|
|
|
_isItemReceived = false;
|
2024-11-26 08:22:26 +00:00
|
|
|
SetItemImage(OrderCocktailData);
|
2024-10-06 23:41:09 +00:00
|
|
|
|
2024-11-25 12:36:48 +00:00
|
|
|
SetTween(waitTime, hurryTime, isReverse);
|
2024-10-06 23:41:09 +00:00
|
|
|
}
|
2024-11-25 12:36:48 +00:00
|
|
|
|
|
|
|
public void OrderItem(Sprite sprite, float waitTime, float hurryTime, bool isReverse = false)
|
2024-10-06 23:41:09 +00:00
|
|
|
{
|
|
|
|
_isOrdered = true;
|
|
|
|
_isWaitTimeOver = false;
|
|
|
|
_isItemReceived = false;
|
|
|
|
SetItemSprite(sprite);
|
2024-06-18 18:16:19 +00:00
|
|
|
ShowUi();
|
2024-11-25 12:36:48 +00:00
|
|
|
|
|
|
|
SetTween(waitTime, hurryTime, isReverse);
|
2024-10-15 18:01:16 +00:00
|
|
|
}
|
2024-06-18 18:16:19 +00:00
|
|
|
|
2024-11-25 12:36:48 +00:00
|
|
|
public void SetTween(float waitTime, float hurryTime, bool isReverse = false)
|
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-25 12:36:48 +00:00
|
|
|
|
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)
|
2024-07-20 11:32:54 +00:00
|
|
|
.SetEase(Ease.Linear)
|
|
|
|
.SetDelay(waitTime)
|
2024-11-25 12:36:48 +00:00
|
|
|
.OnUpdate(() =>
|
|
|
|
{
|
|
|
|
if (_isChangedColor)
|
|
|
|
{
|
|
|
|
UpdateFillColor(_fillImage.fillAmount);
|
|
|
|
}
|
|
|
|
})
|
2024-07-20 11:32:54 +00:00
|
|
|
.OnComplete(OnTweenComplete)
|
2024-11-28 23:07:50 +00:00
|
|
|
.SetAutoKill(false);
|
2024-07-20 11:32:54 +00:00
|
|
|
}
|
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-25 12:36:48 +00:00
|
|
|
|
2024-11-28 23:07:50 +00:00
|
|
|
_fillTween?.Restart();
|
2024-10-28 04:52:11 +00:00
|
|
|
}
|
2024-07-20 11:32:54 +00:00
|
|
|
|
2024-06-18 18:16:19 +00:00
|
|
|
private void OnTweenComplete()
|
|
|
|
{
|
|
|
|
_isWaitTimeOver = true;
|
|
|
|
HideUi();
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsWaitTimeOver() => _isOrdered && _isWaitTimeOver;
|
2024-11-26 08:22:26 +00:00
|
|
|
public bool IsWaitServing() => !_isItemReceived && _isOrdered && !_isWaitTimeOver;
|
2024-09-10 10:25:05 +00:00
|
|
|
public bool IsFoodReceive() => _isItemReceived;
|
2024-06-18 18:16:19 +00:00
|
|
|
|
2024-10-06 23:41:09 +00:00
|
|
|
public void ReceiveItem(IPickup pickupItem)
|
2024-07-02 18:27:56 +00:00
|
|
|
{
|
|
|
|
HideUi();
|
2024-11-26 08:22:26 +00:00
|
|
|
SetEmpty();
|
2024-09-10 10:25:05 +00:00
|
|
|
_isItemReceived = true;
|
2024-07-02 18:27:56 +00:00
|
|
|
}
|
2024-11-25 12:36:48 +00:00
|
|
|
|
|
|
|
private void UpdateFillColor(float fillAmount)
|
|
|
|
{
|
|
|
|
if (fillAmount > 0.6f)
|
|
|
|
{
|
|
|
|
if (_previousColor != _startColor)
|
|
|
|
{
|
|
|
|
_fillImage.color = _startColor;
|
|
|
|
_previousColor = _startColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (fillAmount > 0.3f)
|
|
|
|
{
|
|
|
|
if (_previousColor != _middleColor)
|
|
|
|
{
|
|
|
|
_fillImage.color = _middleColor;
|
|
|
|
_previousColor = _middleColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_previousColor != _endColor)
|
|
|
|
{
|
|
|
|
_fillImage.color = _endColor;
|
|
|
|
_previousColor = _endColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-11-26 08:22:26 +00:00
|
|
|
|
|
|
|
public void SetColor(Color color)
|
|
|
|
{
|
|
|
|
_background.color = color;
|
|
|
|
_itemImage.color = color;
|
|
|
|
}
|
2024-11-25 12:36:48 +00:00
|
|
|
|
|
|
|
public void PauseTween()
|
|
|
|
{
|
2024-11-28 23:07:50 +00:00
|
|
|
if (_fillTween.IsActive() && _fillTween.IsPlaying())
|
2024-11-25 12:36:48 +00:00
|
|
|
{
|
2024-11-28 23:07:50 +00:00
|
|
|
_fillTween?.Pause();
|
2024-11-25 12:36:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ResumeTween()
|
|
|
|
{
|
2024-11-28 23:07:50 +00:00
|
|
|
if (_fillTween.IsActive() && !_fillTween.IsPlaying())
|
2024-11-25 12:36:48 +00:00
|
|
|
{
|
2024-11-28 23:07:50 +00:00
|
|
|
_fillTween?.Play();
|
2024-11-25 12:36:48 +00:00
|
|
|
}
|
|
|
|
}
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
}
|