4a27bd1246e71f20f558e895cd5ac5c1d4ac6f1f.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, BehaviorTree, BTreeNode, BranchNode, _crd;
  4. function _reportPossibleCrUseOfBehaviorTree(extras) {
  5. _reporterNs.report("BehaviorTree", "./BehaviorTree", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfBTreeNode(extras) {
  8. _reporterNs.report("BTreeNode", "./BTreeNode", _context.meta, extras);
  9. }
  10. _export("BranchNode", void 0);
  11. return {
  12. setters: [function (_unresolved_) {
  13. _reporterNs = _unresolved_;
  14. }, function (_cc) {
  15. _cclegacy = _cc.cclegacy;
  16. }, function (_unresolved_2) {
  17. BehaviorTree = _unresolved_2.BehaviorTree;
  18. }, function (_unresolved_3) {
  19. BTreeNode = _unresolved_3.BTreeNode;
  20. }],
  21. execute: function () {
  22. _crd = true;
  23. _cclegacy._RF.push({}, "beafaDMsw9FCbGDpLVmMfa1", "BranchNode", undefined);
  24. /*
  25. * @Author: dgflash
  26. * @Date: 2022-06-21 12:05:14
  27. * @LastEditors: dgflash
  28. * @LastEditTime: 2022-07-20 13:58:32
  29. */
  30. /** 复合节点 */
  31. _export("BranchNode", BranchNode = class BranchNode extends (_crd && BTreeNode === void 0 ? (_reportPossibleCrUseOfBTreeNode({
  32. error: Error()
  33. }), BTreeNode) : BTreeNode) {
  34. constructor(nodes) {
  35. super();
  36. /** 子节点数组 */
  37. this.children = void 0;
  38. /** 当前任务索引 */
  39. this._actualTask = void 0;
  40. /** 正在运行的节点 */
  41. this._runningNode = void 0;
  42. this._nodeRunning = void 0;
  43. /** 外部参数对象 */
  44. this._blackboard = void 0;
  45. this.children = nodes || [];
  46. }
  47. start() {
  48. this._actualTask = 0;
  49. super.start();
  50. }
  51. run(blackboard) {
  52. if (this.children.length == 0) {
  53. // 没有子任务直接视为执行失败
  54. this._control.fail();
  55. } else {
  56. this._blackboard = blackboard;
  57. this.start();
  58. if (this._actualTask < this.children.length) {
  59. this._run();
  60. }
  61. }
  62. this.end();
  63. }
  64. /** 执行当前节点逻辑 */
  65. _run(blackboard) {
  66. var node = (_crd && BehaviorTree === void 0 ? (_reportPossibleCrUseOfBehaviorTree({
  67. error: Error()
  68. }), BehaviorTree) : BehaviorTree).getNode(this.children[this._actualTask]);
  69. this._runningNode = node;
  70. node.setControl(this);
  71. node.start(this._blackboard);
  72. node.run(this._blackboard);
  73. }
  74. running(node) {
  75. this._nodeRunning = node;
  76. this._control.running(node);
  77. }
  78. success() {
  79. this._nodeRunning = null;
  80. this._runningNode.end(this._blackboard);
  81. }
  82. fail() {
  83. this._nodeRunning = null;
  84. this._runningNode.end(this._blackboard);
  85. }
  86. });
  87. _cclegacy._RF.pop();
  88. _crd = false;
  89. }
  90. };
  91. });
  92. //# sourceMappingURL=4a27bd1246e71f20f558e895cd5ac5c1d4ac6f1f.js.map