using System.Collections.Generic; using Sirenix.OdinInspector; using Sirenix.Serialization; using UnityEngine; using UnityEngine.UI; namespace DDD.Restaurant { public class CustomerPatienceUiComponent : SerializedMonoBehaviour { private IAISharedBlackboard _blackboard; [OdinSerialize] private HashSet _targetOrderType = new(); [SerializeField] private RestaurantOrderType _currentOrderType; [SerializeField] private RestaurantOrderType _prevOrderType; private bool _initialized; private IInteractionSubsystemObject _subsystem; [SerializeField] private Slider _patienceSlider; private void Start() { var canvas = GetComponentInChildren(); canvas.worldCamera = Camera.main; _patienceSlider = GetComponentInChildren(); if (_patienceSlider == null) { Debug.LogWarning($"[{GetType().Name}] 슬라이더가 존재하지 않음 오브젝트 해시코드: {gameObject.GetHashCode()}"); return; } if (!TryGetComponent(out _blackboard)) { Debug.LogWarning($"[{GetType().Name}] 블랙보드가 존재하지 않음 오브젝트 해시코드: {gameObject.GetHashCode()}"); return; } var targetObject = _blackboard.GetBlackboardValue(RestaurantCustomerBlackboardKey.CurrentTargetGameObject); if (targetObject == null) { Debug.LogWarning($"[{GetType().Name}] 타겟 오브젝트가 존재하지 않음 오브젝트 해시코드: {gameObject.GetHashCode()}"); return; } if (!targetObject.TryGetComponent(out var subsystemOwner)) { Debug.LogWarning($"[{GetType().Name}] 서브시스템 오너가 존재하지 않음 오브젝트 해시코드: {gameObject.GetHashCode()}"); return; } subsystemOwner.TryGetSubsystemObject(out _subsystem); if (_subsystem == null) { Debug.LogWarning($"[{GetType().Name}] RestaurantOrderType 서브시스템이 존재하지 않음 오브젝트 해시코드: {gameObject.GetHashCode()}"); return; } _currentOrderType = _subsystem.GetInteractionSubsystemType(); _initialized = true; _patienceSlider.gameObject.SetActive(false); } private void Update() { if (!_initialized) return; _currentOrderType = _subsystem.GetInteractionSubsystemType(); if (!_targetOrderType.Contains(_currentOrderType)) { _patienceSlider.gameObject.SetActive(false); return; } if (_currentOrderType != _prevOrderType) { SetPatience(); } if (_currentOrderType == RestaurantOrderType.Busy) { _patienceSlider.maxValue = _blackboard.GetBlackboardValue(RestaurantCustomerBlackboardKey.MaxPatienceTime); var remainingTime = _blackboard.GetBlackboardValue(RestaurantCustomerBlackboardKey.RemainingPatienceTime); _patienceSlider.value = _patienceSlider.maxValue - remainingTime; if (_patienceSlider.value >= _patienceSlider.maxValue) { _patienceSlider.gameObject.SetActive(false); } } else { _patienceSlider.maxValue = _blackboard.GetBlackboardValue(RestaurantCustomerBlackboardKey.MaxPatienceTime); _patienceSlider.value = _blackboard.GetBlackboardValue(RestaurantCustomerBlackboardKey.RemainingPatienceTime); if (_patienceSlider.value <= 0) { _patienceSlider.gameObject.SetActive(false); } } } private void SetPatience() { _prevOrderType = _currentOrderType; _patienceSlider.maxValue = _blackboard.GetBlackboardValue(RestaurantCustomerBlackboardKey.MaxPatienceTime); _patienceSlider.value = _patienceSlider.maxValue; ColorBlock colors = _patienceSlider.colors; colors.normalColor = _currentOrderType == RestaurantOrderType.Busy ? Color.green : Color.red; _patienceSlider.colors = colors; _patienceSlider.gameObject.SetActive(true); } } }