96c82e142a8935f51d331cdf55183d0b307050b4.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, BTreeNode, BehaviorTree, _crd, countUnnamed;
  4. function _reportPossibleCrUseOfBTreeNode(extras) {
  5. _reporterNs.report("BTreeNode", "./BTreeNode", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfIControl(extras) {
  8. _reporterNs.report("IControl", "./IControl", _context.meta, extras);
  9. }
  10. _export("BehaviorTree", void 0);
  11. return {
  12. setters: [function (_unresolved_) {
  13. _reporterNs = _unresolved_;
  14. }, function (_cc) {
  15. _cclegacy = _cc.cclegacy;
  16. }, function (_unresolved_2) {
  17. BTreeNode = _unresolved_2.BTreeNode;
  18. }],
  19. execute: function () {
  20. _crd = true;
  21. _cclegacy._RF.push({}, "22a91RP3fNG/rWWAXlmM4BT", "BehaviorTree", undefined);
  22. countUnnamed = 0;
  23. /** 行为树 */
  24. _export("BehaviorTree", BehaviorTree = class BehaviorTree {
  25. /** 是否已开始执行 */
  26. get started() {
  27. return this._started;
  28. }
  29. /**
  30. * 构造函数
  31. * @param node 根节点
  32. * @param blackboard 外部参数对象
  33. */
  34. constructor(node, blackboard) {
  35. this.title = void 0;
  36. /** 根节点 */
  37. this._root = void 0;
  38. /** 当前执行节点 */
  39. this._current = void 0;
  40. /** 是否已开始执行 */
  41. this._started = false;
  42. /** 外部参数对象 */
  43. this._blackboard = void 0;
  44. countUnnamed += 1;
  45. this.title = node.constructor.name + '(btree_' + countUnnamed + ')';
  46. this._root = node;
  47. this._blackboard = blackboard;
  48. }
  49. /** 设置行为逻辑中的共享数据 */
  50. setObject(blackboard) {
  51. this._blackboard = blackboard;
  52. }
  53. /** 执行行为树逻辑 */
  54. run() {
  55. if (this._started) {
  56. console.error("\u884C\u4E3A\u6811\u3010" + this.title + "\u3011\u672A\u8C03\u7528\u6B65\u9AA4\uFF0C\u5728\u6700\u540E\u4E00\u6B21\u8C03\u7528\u6B65\u9AA4\u65F6\u6709\u4E00\u4E2A\u4EFB\u52A1\u672A\u5B8C\u6210");
  57. }
  58. this._started = true;
  59. var node = BehaviorTree.getNode(this._root);
  60. this._current = node;
  61. node.setControl(this);
  62. node.start(this._blackboard);
  63. node.run(this._blackboard);
  64. }
  65. running(node) {
  66. this._started = false;
  67. }
  68. success() {
  69. this._current.end(this._blackboard);
  70. this._started = false;
  71. }
  72. fail() {
  73. this._current.end(this._blackboard);
  74. this._started = false;
  75. }
  76. /** ---------------------------------------------------------------------------------------------------- */
  77. static register(name, node) {
  78. this._registeredNodes.set(name, node);
  79. }
  80. static getNode(name) {
  81. var node = name instanceof (_crd && BTreeNode === void 0 ? (_reportPossibleCrUseOfBTreeNode({
  82. error: Error()
  83. }), BTreeNode) : BTreeNode) ? name : this._registeredNodes.get(name);
  84. if (!node) {
  85. throw new Error("\u65E0\u6CD5\u627E\u5230\u8282\u70B9\u3010" + name + "\u3011\uFF0C\u53EF\u80FD\u5B83\u6CA1\u6709\u6CE8\u518C\u8FC7");
  86. }
  87. return node;
  88. }
  89. });
  90. BehaviorTree._registeredNodes = new Map();
  91. _cclegacy._RF.pop();
  92. _crd = false;
  93. }
  94. };
  95. });
  96. //# sourceMappingURL=96c82e142a8935f51d331cdf55183d0b307050b4.js.map