CapersProject/Assets/02.Scripts/Tycoon/CustomerTableController.cs
2024-09-12 13:17:34 +09:00

46 lines
1.2 KiB
C#

using System.Collections.Generic;
using System.Linq;
using BlueWater.Utility;
using UnityEngine;
using Random = System.Random;
namespace BlueWater.Tycoons
{
public class CustomerTableController : MonoBehaviour
{
[SerializeField]
private List<CustomerTable> _customerTables;
private Random _random = new();
public void RegisterTable(CustomerTable table)
{
Utils.RegisterList(_customerTables, table);
}
public void UnregisterTable(CustomerTable table)
{
Utils.UnregisterList(_customerTables, table);
}
public TableSeat FindEmptySeat()
{
var tableCount = _customerTables.Count;
var indices = new List<int>(Enumerable.Range(0, tableCount));
while (indices.Count > 0)
{
var randomIndex = _random.Next(indices.Count);
var tableIndex = indices[randomIndex];
indices.RemoveAt(randomIndex);
var emptySeat = _customerTables[tableIndex].FindEmptySeat();
if (emptySeat != null)
{
return emptySeat;
}
}
return null;
}
}
}