using System.Collections.Generic; using BlueWater.Npcs.Customers; using Sirenix.OdinInspector; using Spine.Unity; using UnityEngine; namespace BlueWater { public class BillUi : MonoBehaviour { [SerializeField] private Bill _billPrefab; [SerializeField] private SkeletonGraphic _chain; [Title("계산서")] [SerializeField] private Vector3 _spawnPosition; [SerializeField] private Transform _spawnLocation; [SerializeField] private List _billInfos = new(5); private Dictionary _customerBillDictionary = new(); private bool _isMovedChain; private const string Move = "Move"; private void Start() { EventManager.OnOrderedCocktail += OrderedCocktail; EventManager.OnOrderResult += OrderResult; } private void OnDestroy() { EventManager.OnOrderedCocktail -= OrderedCocktail; EventManager.OnOrderResult -= OrderResult; } private void OrderedCocktail(Customer customer) { var instance = Instantiate(_billPrefab, _spawnLocation); instance.Initialize(customer, _spawnPosition, _billInfos[0].Position); _customerBillDictionary.Add(customer, instance); UpdateBillInfo(); } private void OrderResult(Customer customer, bool isSucceed) { if (_customerBillDictionary.TryGetValue(customer, out Bill bill)) { bill.OrderResult(isSucceed, UpdateBillInfo); _customerBillDictionary.Remove(customer); UpdateBillInfo(); // Bill이 제거된 후 빈 자리를 업데이트 } } private void UpdateBillInfo() { foreach (var element in _customerBillDictionary.Values) { for (var i = 0; i < _billInfos.Count; i++) { if (element.CurrentBillInfo == _billInfos[i]) break; if (_billInfos[i].IsEmpty) { PlayChainAnimation(); element.Move(_billInfos[i]); break; } } } Invoke(nameof(StopChainAnimation), 1f); } private void PlayChainAnimation() { _chain.AnimationState.SetAnimation(0, Move, true); _isMovedChain = true; } private void StopChainAnimation() { if (!_isMovedChain) return; _chain.AnimationState.ClearTrack(0); _isMovedChain = false; } } }