1 BehaviorTreeNode = {}
 2 
 3 BehaviorTreeNode.Type = {
 4     ACTION = "ACTION",
 5     CONDITION = "CONDITION",
 6     SELECTOR = "SELECTOR",
 7     SEQUENCE = "SEQUENCE"
 8 }
 9 
10 function BehaviorTreeNode.new(name,type)
11     local node = {}
12 
13     node.action_ = nil
14     node.children_ = {}
15     node.evaluator_ = nil
16     node.name_ = name or ""
17     node.parent_ = nil
18     node.type_ = type or BehaviorTreeNode.Type.ACTION
19 
20     node.AddChild = BehaviorTreeNode.AddChild
21     node.ChildIndex = BehaviorTreeNode.ChildIndex
22     node.GetChild = BehaviorTreeNode.GetChild
23     node.GetNumberOfChildren = BehaviorTreeNode.GetNumberOfChildren
24 
25     node.GetParent = BehaviorTreeNode.GetParent
26     node.SetAction = BehaviorTreeNode.SetAction
27     node.SetEvaluator = BehaviorTreeNode.SetEvaluator
28     node.SetType = BehaviorTreeNode.SetType
29 
30     return node
31 end
32 
33 function BehaviorTreeNode.AddChild(self,child,index)
34     index = index or (#self.children_ + 1)
35     table.insert(self.children_,index,child)
36     child.parent_ = self
37 end
38 
39 function BehaviorTreeNode.ChildIndex(self,child)
40     for index = 1, #self.children_ do
41         if self.children_[index] == child then
42             return index
43         end
44     end
45 
46     return -1
47 end
48 
49 function BehaviorTreeNode.GetChild(self,childIndex)
50     return self.children_[childIndex]
51 end
52 
53 function BehaviorTreeNode.GetNumberOfChildren(self)
54     return #self.children_
55 end
56 
57 function BehaviorTreeNode.GetParent(self)
58     return self.parent_
59 end
60 
61 function BehaviorTreeNode.SetAction(self,action)
62     self.action_ = action
63 end
64 
65 function BehaviorTreeNode.SetEvaluator(self,evaluator)
66     self.evaluator_ = evaluator
67 end
68 
69 function BehaviorTreeNode.SetType(self,type)
70     self.type_ = type
71 end
BehaviorTreeNode

相关文章:

  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
猜你喜欢
  • 2021-06-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
相关资源
相似解决方案