using System; using System.Threading.Tasks; using Opsive.BehaviorDesigner.Runtime; using Unity.Entities; using UnityEngine; using UnityEngine.AddressableAssets; namespace DDD { [RequireComponent(typeof(BehaviorTree))] [RequireComponent(typeof(RestaurantCustomerBlackboardComponent))] public class RestaurantCustomerAiComponent : MonoBehaviour, IRestaurantCustomerAi { protected BehaviorTree _behaviorTree; protected RestaurantCustomerBlackboardComponent _blackboardComponent; private void Awake() { _behaviorTree = GetComponent(); _blackboardComponent = GetComponent(); } public void InitializeAi(CustomerData inCustomerData) { try { InitializeAiInternal(inCustomerData); } catch (Exception e) { // Log Debug.LogError(e); throw; // TODO 예외 처리 } } private async Task InitializeAiInternal(CustomerData inCustomerData) { var customerState = RestaurantState.Instance.CustomerState; var subtree = customerState.GetLoadedSubtree(inCustomerData.CustomerType); if (subtree == null) { Debug.LogError( $"[CustomerCharacter] No preloaded subtree found for CustomerType: {inCustomerData.CustomerType}. Make sure CustomerBehaviorData is loaded."); subtree = await customerState.GetOrLoadSubtree(inCustomerData.CustomerType); } _behaviorTree.Subgraph = subtree; _blackboardComponent.InitializeWithBehaviorTree(subtree); _blackboardComponent.SetCustomerData(inCustomerData); // TODO : 1. Subtree - Action, Condition // TODO : 2. Blackboard _behaviorTree.StartBehavior(); } } }