233 lines
6.1 KiB
C#
233 lines
6.1 KiB
C#
using System;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Items;
|
|
using DG.Tweening;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class BalloonUi : MonoBehaviour
|
|
{
|
|
[Title("컴포넌트")]
|
|
[SerializeField]
|
|
private Image _background;
|
|
|
|
[SerializeField, Required]
|
|
private Image _fillImage;
|
|
|
|
[SerializeField, Required]
|
|
private Image _itemImage;
|
|
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[Title("색상 변경 연출")]
|
|
[SerializeField]
|
|
private bool _isChangedColor;
|
|
|
|
[SerializeField]
|
|
private Color _startColor = Color.green;
|
|
|
|
[SerializeField]
|
|
private Color _middleColor = Color.yellow;
|
|
|
|
[SerializeField]
|
|
private Color _endColor = Color.red;
|
|
|
|
[Title("주문 정보")]
|
|
[SerializeField, DisableIf("@true")]
|
|
private bool _isOrdered;
|
|
|
|
[SerializeField, DisableIf("@true")]
|
|
private bool _isWaitTimeOver;
|
|
|
|
[SerializeField, DisableIf("@true")]
|
|
private bool _isItemReceived;
|
|
|
|
public CocktailData OrderCocktailData { get; private set; }
|
|
|
|
private Tween _fillTween;
|
|
private Color _previousColor;
|
|
|
|
private void Awake()
|
|
{
|
|
InitializeComponents();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_fillTween?.Kill();
|
|
}
|
|
|
|
[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();
|
|
}
|
|
|
|
private void ResetUi()
|
|
{
|
|
_isOrdered = false;
|
|
_isWaitTimeOver = false;
|
|
_isItemReceived = false;
|
|
}
|
|
|
|
private void SetEmpty()
|
|
{
|
|
SetItemSprite(null);
|
|
OrderCocktailData = null;
|
|
_fillTween?.Kill();
|
|
}
|
|
|
|
public void SetItemSprite(Sprite sprite)
|
|
{
|
|
_itemImage.sprite = sprite;
|
|
}
|
|
|
|
public void DiscardItem()
|
|
{
|
|
HideUi();
|
|
SetEmpty();
|
|
ResetUi();
|
|
}
|
|
|
|
public void OrderItem(string itemIdx, float waitTime, float hurryTime, bool isReverse = false)
|
|
{
|
|
OrderCocktailData = ItemManager.Instance.CocktailDataSo.GetDataByIdx(itemIdx);
|
|
_isOrdered = true;
|
|
_isWaitTimeOver = false;
|
|
_isItemReceived = false;
|
|
SetItemImage(OrderCocktailData);
|
|
|
|
SetTween(waitTime, hurryTime, isReverse);
|
|
}
|
|
|
|
public void OrderItem(Sprite sprite, float waitTime, float hurryTime, bool isReverse = false)
|
|
{
|
|
_isOrdered = true;
|
|
_isWaitTimeOver = false;
|
|
_isItemReceived = false;
|
|
SetItemSprite(sprite);
|
|
ShowUi();
|
|
|
|
SetTween(waitTime, hurryTime, isReverse);
|
|
}
|
|
|
|
public void SetTween(float waitTime, float hurryTime, bool isReverse = false)
|
|
{
|
|
float startValue = isReverse ? 1f : 0f;
|
|
float endValue = isReverse ? 0f : 1f;
|
|
|
|
_fillTween?.Kill();
|
|
_fillTween = _fillImage.DOFillAmount(endValue, hurryTime)
|
|
.From(startValue)
|
|
.SetEase(Ease.Linear)
|
|
.SetDelay(waitTime)
|
|
.OnUpdate(() =>
|
|
{
|
|
if (_isChangedColor)
|
|
{
|
|
UpdateFillColor(_fillImage.fillAmount);
|
|
}
|
|
})
|
|
.OnComplete(OnTweenComplete)
|
|
.SetAutoKill(false);
|
|
}
|
|
|
|
public void ResetGauge()
|
|
{
|
|
if (_fillTween == null)
|
|
{
|
|
Debug.LogError("BalloonUi 게이지 리셋 오류");
|
|
return;
|
|
}
|
|
|
|
_fillTween?.Restart();
|
|
}
|
|
|
|
private void OnTweenComplete()
|
|
{
|
|
_isWaitTimeOver = true;
|
|
HideUi();
|
|
}
|
|
|
|
public bool IsWaitTimeOver() => _isOrdered && _isWaitTimeOver;
|
|
public bool IsWaitServing() => !_isItemReceived && _isOrdered && !_isWaitTimeOver;
|
|
public bool IsFoodReceive() => _isItemReceived;
|
|
|
|
public void ReceiveItem(IPickup pickupItem)
|
|
{
|
|
HideUi();
|
|
SetEmpty();
|
|
_isItemReceived = true;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetColor(Color color)
|
|
{
|
|
_background.color = color;
|
|
_itemImage.color = color;
|
|
}
|
|
|
|
public void PauseTween()
|
|
{
|
|
if (_fillTween.IsActive() && _fillTween.IsPlaying())
|
|
{
|
|
_fillTween?.Pause();
|
|
}
|
|
}
|
|
|
|
public void ResumeTween()
|
|
{
|
|
if (_fillTween.IsActive() && !_fillTween.IsPlaying())
|
|
{
|
|
_fillTween?.Play();
|
|
}
|
|
}
|
|
}
|
|
} |