2025-08-12 11:46:30 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace DDD
|
|
|
|
{
|
|
|
|
public interface ICustomerFactory
|
|
|
|
{
|
|
|
|
Task<GameObject> CreateAsync(CustomerSpawnArgs args);
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface ICustomerInitializer
|
|
|
|
{
|
2025-08-13 03:56:52 +00:00
|
|
|
void Initialize(CustomerData customerData);
|
2025-08-12 11:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public struct CustomerSpawnArgs
|
|
|
|
{
|
|
|
|
public CustomerData CustomerData;
|
|
|
|
public Vector3 Position;
|
|
|
|
public Quaternion Rotation;
|
|
|
|
public Transform Parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public class CustomerFactory : ICustomerFactory
|
|
|
|
{
|
|
|
|
private GameObject _customerPrefab;
|
|
|
|
|
|
|
|
public async Task<GameObject> CreateAsync(CustomerSpawnArgs args)
|
|
|
|
{
|
|
|
|
if (!_customerPrefab)
|
|
|
|
{
|
|
|
|
_customerPrefab = await AssetManager.LoadAsset<GameObject>(DataConstants.CustomerNpcPrefab);
|
|
|
|
}
|
|
|
|
|
|
|
|
var newCustomer = Object.Instantiate(_customerPrefab, args.Position, args.Rotation, args.Parent);
|
|
|
|
|
|
|
|
if (newCustomer.TryGetComponent(out ICustomerInitializer initializer))
|
|
|
|
{
|
2025-08-13 03:56:52 +00:00
|
|
|
initializer.Initialize(args.CustomerData);
|
2025-08-12 11:46:30 +00:00
|
|
|
}
|
|
|
|
return newCustomer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|