NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/AI/AIManager.cs

62 lines
1.7 KiB
C#
Raw Normal View History

2023-08-22 19:08:45 +08:00
using System.Collections.Generic;
using BehaviorDesigner.Runtime;
using Cysharp.Threading.Tasks;
2024-09-18 14:38:27 +08:00
using Gameplay.BT.Variables;
2023-08-22 19:08:45 +08:00
using Gameplay.BT;
using UnityEngine;
2024-09-18 14:38:27 +08:00
using PhxhSDK;
2023-08-22 19:08:45 +08:00
namespace Gameplay.AI
{
public class AIManager : Singlenton<AIManager>, IInitable, IUpdatable
{
2024-09-18 14:38:27 +08:00
private const string SharedVariableName = "battleInfo";
2023-08-22 19:08:45 +08:00
private BTImplement _iaiImplement;
public void Init()
{
_iaiImplement = BTImplement.Instance;
_iaiImplement.Init();
}
public void Release()
{
_iaiImplement.Release();
}
public void Update(float deltaTime)
{
_iaiImplement.Update(deltaTime);
}
2024-09-14 15:12:37 +08:00
2024-09-18 14:38:27 +08:00
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;
}
2024-09-14 15:12:37 +08:00
public async UniTask<BehaviorTree> RegisterAI(GameObject go, string aiName, bool enable = true)
2023-08-22 19:08:45 +08:00
{
2024-09-14 15:12:37 +08:00
return await _iaiImplement.RegisterAI(go, aiName, enable);
2023-08-22 19:08:45 +08:00
}
public void UnRegisterAI(GameObject go)
{
_iaiImplement.UnRegisterAI(go);
}
2024-09-14 15:12:37 +08:00
2023-08-22 19:08:45 +08:00
public async UniTask PreLoadAI(HashSet<string> aiNames, int initCount)
{
await _iaiImplement.PreLoadAI(aiNames, initCount);
}
}
2024-09-14 15:12:37 +08:00
}