Files
Main/Assets/GameAssets/Resources/Lua/Logic/AI/AIManager.lua
2025-01-25 04:38:09 +08:00

51 lines
1.4 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

------------------------------------------------
--作者xihan
--日期2019-07-04
--文件AIManager.lua
--模块AIManager
--描述场景中有AI的实体的管理器
------------------------------------------------
local AIManager = {
--当前正在执行的状态机
AllStateMachine = {},
--状态机池
StateMachinePool = {},
};
--绑定FSM
function AIManager:Bind(owner, configid)
if self.AllStateMachine[owner] then
if self.AllStateMachine[owner].ConfigId ~= configid then
self.AllStateMachine[owner]:SetConfig(configid);
end
else
if #self.StateMachinePool > 0 then
self.AllStateMachine[owner] = table.remove(self.StateMachinePool,1);
self.AllStateMachine[owner]:SetOwner(owner);
self.AllStateMachine[owner]:SetConfig(configid);
else
self.AllStateMachine[owner] = StateMachine:New(owner, configid);
end
end
end
--解除绑定FSM
function AIManager:UnBind(owner)
local _machine = self.AllStateMachine[owner];
if _machine then
_machine:Clear();
_machine.Owner = nil;
table.insert(self.StateMachinePool, _machine);
self.AllStateMachine[owner] = nil;
end
end
--更新
function AIManager:Update(dt)
for _,v in pairs(self.AllStateMachine) do
v:Update(dt);
end
end
return AIManager;