2025-06-04 05:02:57 +08:00

61 lines
1.5 KiB
Plaintext
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.

--順序結點,邏輯與執行到第一個為failure的節點便停止
autoImport("LParentNode")
LSequenceNode = class('LSequenceNode',LParentNode)
function LSequenceNode:ctor(behaviorTree)
LSequenceNode.super.ctor(self,behaviorTree)
self.conditionNodes = {}
end
function LSequenceNode:AddCondNode(node)
if(TableUtil.ArrayIndexOf(self.conditionNodes,node)==0) then
self.conditionNodes[#self.conditionNodes + 1] = node
end
LNode.SetParentNode (node, self);
end
function LSequenceNode:RemoveCondNode( node )
if(TableUtil.ArrayIndexOf(self.conditionNodes,node)>0) then
TableUtil.Remove(self.conditionNodes,node)
end
LNode.SetParentNode (node, nil);
end
function LSequenceNode:OnConditionNodesUpdate()
if(#self.conditionNodes == 0) then
return TaskState.Success
end
local node,state
for i=1,#self.conditionNodes do
node = self.conditionNodes [i]
state = node:Update()
if(state == TaskState.Failure) then
return state
end
end
return TaskState.Success
end
function LSequenceNode:OnChildrenNodesUpdate()
if(#self.childrenNodes == 0) then
return TaskState.Success
end
local node,state
for i=1,#self.childrenNodes do
node = self.childrenNodes [i]
state = node:Update()
if (state == TaskState.Failure) then
return state
end
end
return state
end
function LSequenceNode:Update()
local result = self:OnConditionNodesUpdate()
-- print("sequence",result)
if(result == TaskState.Success) then
result = self:OnChildrenNodesUpdate ()
end
return result
end