62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
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<AIManager>, 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<BehaviorTree> 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<string> aiNames, int initCount)
|
|
{
|
|
await _iaiImplement.PreLoadAI(aiNames, initCount);
|
|
}
|
|
}
|
|
} |