--- --- Generated by EmmyLua(https://github.com/EmmyLua) --- Created by xxn. --- DateTime: 2021/1/7 14:30 --- ---@class BehaviorTree BehaviorTree = class() local this = BehaviorTree ---@type table this.bts = {} ---@param root BehaviorNode function BehaviorTree:ctor(root, owner) self.root = root --行为树根节点 self.root:SetOwner(owner) end function this.UpdateAll() for k, v in pairs(this.bts) do v:Update() end end function BehaviorTree:Update() self.root:Visit() self:HandleStatus() self.root:SaveStatus() self.root:Step() end function BehaviorTree:Reset() self.root:Reset() end function BehaviorTree:Stop() self.root:Stop() end function BehaviorTree:HandleStatus() if self.statusCallback and self.root.status == self.status then self.statusCallback() end end function BehaviorTree:SetStateCallback(callback, status) self.statusCallback = callback self.status = status end function BehaviorTree:Start() --local function StartBehaviorTree() -- -- while true do -- self:Update() -- Coroutine.WaitForEndOfFrame() -- end -- --end if not table.contains(this.bts,self) then table.insert(this.bts,self) end self.isStart = true --if self.loopBehavior == nil then -- self.loopBehavior = Coroutine.Start(StartBehaviorTree) --end end function BehaviorTree:Cancel() self:Reset() self.isStart = false --if self.loopBehavior then Coroutine.Stop(self.loopBehavior) self.loopBehavior = nil end table.removeByValue(this.bts,self) end function BehaviorTree:IsUpdateIn() --return self.loopBehavior and true or false return self.isStart end