using System.Collections.Generic; using BehaviorDesigner.Runtime; using Cysharp.Threading.Tasks; using Gameplay.BT.Variables; using Gameplay.BT; using UnityEngine; using PhxhSDK; namespace Gameplay.AI { public class AIManager : Singlenton, IInitable, IUpdatable { private const string SharedVariableName = "battleInfo"; private BTImplement _iaiImplement; public void Init() { _iaiImplement = BTImplement.Instance; _iaiImplement.Init(); } public void Release() { _iaiImplement.Release(); } public void Update(float deltaTime) { _iaiImplement.Update(deltaTime); } public bool EnableAI(GameObject go, bool enable) { var bt = _iaiImplement.GetAITree(go); if (bt != null && bt.GetVariable(SharedVariableName) is SharedBattleInfo sharedVariable) { var battleInfo = sharedVariable.Value; battleInfo.AutoFight = enable; sharedVariable.Value = battleInfo; bt.SetVariable(SharedVariableName, sharedVariable); return true; } return false; } public async UniTask RegisterAI(GameObject go, string aiName, bool enable = true) { return await _iaiImplement.RegisterAI(go, aiName, enable); } public void UnRegisterAI(GameObject go) { _iaiImplement.UnRegisterAI(go); } public async UniTask PreLoadAI(HashSet aiNames, int initCount) { await _iaiImplement.PreLoadAI(aiNames, initCount); } } }