+ 전투에서 사용되는 Item 오브젝트의 InteractionUi의 camera를 UiCamera로 연동 + Item의 드랍 방식을 같은 위치에서 랜덤한 위치로 흩뿌리는 방식으로 변경 + 술통, 쓰레기통 상호작용 추가 + 손님이 음료를 요구할 때, 음료 전달 기능 추가 + 가구 Opaque Unlit으로 재질 변경
101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BlueWater.Npcs.Customers;
|
|
using BlueWater.Utility;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
public class CustomerManager : MonoBehaviour
|
|
{
|
|
[Title("손님 데이터")]
|
|
[SerializeField, Required]
|
|
private Customer _customerPrefab;
|
|
|
|
[SerializeField, Required]
|
|
private Transform _customerSpawnTransform;
|
|
|
|
[Title("대기중인 손님 정보")]
|
|
[SerializeField]
|
|
private float _checkEmptySeatInterval = 0.5f;
|
|
|
|
[SerializeField]
|
|
private List<Customer> _instanceCustomers = new();
|
|
|
|
[ShowInInspector]
|
|
private Queue<Customer> _waitingCustomers = new();
|
|
|
|
private CustomerTableManager _customerTableManager;
|
|
private Coroutine _findEmptySeatCoroutineInstance;
|
|
|
|
private void Start()
|
|
{
|
|
_customerTableManager = TycoonManager.Instance.CustomerTableManager;
|
|
}
|
|
|
|
public void InstantiateCustomer()
|
|
{
|
|
var newCustomer = Instantiate(_customerPrefab, _customerSpawnTransform.position, Quaternion.identity);
|
|
newCustomer.Initialize();
|
|
RegisterCustomer(newCustomer);
|
|
}
|
|
|
|
public void TryFindEmptySeat(Customer customer)
|
|
{
|
|
// 이미 대기열에 사람들이 있는 경우, 새로운 손님도 바로 대기열에 넣는다.
|
|
if (_waitingCustomers.Count > 0)
|
|
{
|
|
_waitingCustomers.Enqueue(customer);
|
|
return;
|
|
}
|
|
|
|
// 대기열에는 아무도 없는 경우
|
|
var emptySeat = _customerTableManager.FindEmptySeat();
|
|
if (emptySeat == null)
|
|
{
|
|
// 내가 첫 대기열 손님이 된다.
|
|
_waitingCustomers.Enqueue(customer);
|
|
Utils.StartUniqueCoroutine(this, ref _findEmptySeatCoroutineInstance, CheckEmptySeatCoroutine());
|
|
return;
|
|
}
|
|
|
|
customer.SetTableSeat(emptySeat);
|
|
emptySeat.ReserveSeat();
|
|
customer.AIMovement.Move(emptySeat.SeatTransform.position);
|
|
}
|
|
|
|
private IEnumerator CheckEmptySeatCoroutine()
|
|
{
|
|
var checkEmptySeatInterval = new WaitForSeconds(_checkEmptySeatInterval);
|
|
while (_waitingCustomers.Count > 0)
|
|
{
|
|
var emptySeat = _customerTableManager.FindEmptySeat();
|
|
if (emptySeat != null)
|
|
{
|
|
var customer = _waitingCustomers.Dequeue();
|
|
customer.SetTableSeat(emptySeat);
|
|
emptySeat.ReserveSeat();
|
|
customer.AIMovement.Move(emptySeat.SeatTransform.position);
|
|
|
|
continue;
|
|
}
|
|
|
|
yield return checkEmptySeatInterval;
|
|
}
|
|
|
|
_findEmptySeatCoroutineInstance = null;
|
|
}
|
|
|
|
public void RegisterCustomer(Customer customer)
|
|
{
|
|
Utils.RegisterList(_instanceCustomers, customer);
|
|
}
|
|
|
|
public void UnregisterCustomer(Customer customer)
|
|
{
|
|
Utils.UnregisterList(_instanceCustomers, customer);
|
|
}
|
|
}
|
|
}
|