ProjectDDD/Assets/_DDD/_Scripts/RestaurantCharacter/Npc/Customer/CustomerCharacter.cs

52 lines
1.8 KiB
C#

using System.Threading.Tasks;
using Opsive.BehaviorDesigner.Runtime;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace DDD
{
public class CustomerCharacter : RestaurantNpcCharacter, ICustomerInitializer
{
private CustomerData _customerData;
public async void Initialize(CustomerData customerData)
{
_customerData = customerData;
// 스킨 설정
_spineController.SetSkin(_customerData.SpineSkinKey);
// CustomerType에 따른 behavior tree subtree 할당
await InitializeBehaviorTree();
}
private async Task InitializeBehaviorTree()
{
var customerData = RestaurantData.Instance.CustomerData;
if (customerData?.CustomerBehaviorData?.TryGetValue(_customerData.CustomerType, out var subtreeReference) != true)
{
Debug.LogError($"[CustomerCharacter] No behavior data found for CustomerType: {_customerData.CustomerType}");
return;
}
try
{
var subtree = await subtreeReference.LoadAssetAsync<Subtree>().Task;
if (subtree != null)
{
_behaviorTree.Subgraph = subtree;
_behaviorTree.StartBehavior();
}
else
{
Debug.LogError($"[CustomerCharacter] Failed to load subtree for CustomerType: {_customerData.CustomerType}");
}
}
catch (System.Exception e)
{
Debug.LogError($"[CustomerCharacter] Error loading subtree for CustomerType {_customerData.CustomerType}: {e.Message}");
}
}
}
}