fd0fb4b89f94c1b95d1edde75f9c1d445e7a402f.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. System.register(["__unresolved_0", "cc", "__unresolved_1", "__unresolved_2"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, error, AnimatorParams, AnimatorState, AnimatorController, _crd;
  4. function _reportPossibleCrUseOfAnimatorBase(extras) {
  5. _reporterNs.report("AnimatorBase", "./AnimatorBase", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfAnimatorParams(extras) {
  8. _reporterNs.report("AnimatorParams", "./AnimatorParams", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfAnimatorState(extras) {
  11. _reporterNs.report("AnimatorState", "./AnimatorState", _context.meta, extras);
  12. }
  13. _export("default", void 0);
  14. return {
  15. setters: [function (_unresolved_) {
  16. _reporterNs = _unresolved_;
  17. }, function (_cc) {
  18. _cclegacy = _cc.cclegacy;
  19. __checkObsolete__ = _cc.__checkObsolete__;
  20. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  21. error = _cc.error;
  22. }, function (_unresolved_2) {
  23. AnimatorParams = _unresolved_2.default;
  24. }, function (_unresolved_3) {
  25. AnimatorState = _unresolved_3.default;
  26. }],
  27. execute: function () {
  28. _crd = true;
  29. _cclegacy._RF.push({}, "01df9SMBjRCyYDE7SgbZxua", "AnimatorController", undefined);
  30. __checkObsolete__(['error']);
  31. /**
  32. * 状态机控制类
  33. */
  34. _export("default", AnimatorController = class AnimatorController {
  35. /** 当前运行的状态 */
  36. get curState() {
  37. return this._curState;
  38. }
  39. get params() {
  40. return this._params;
  41. }
  42. get states() {
  43. return this._states;
  44. }
  45. constructor(player, json) {
  46. this._jsonData = null;
  47. this._animator = null;
  48. this._params = null;
  49. this._states = null;
  50. this._anyState = null;
  51. this._curState = null;
  52. /** 状态切换次数 */
  53. this._changeCount = 0;
  54. /** 对应animComplete的状态 */
  55. this.animCompleteState = null;
  56. /** 动画播放完毕的标记 */
  57. this.animComplete = false;
  58. this._animator = player;
  59. this._jsonData = json;
  60. this._states = new Map();
  61. this._params = new (_crd && AnimatorParams === void 0 ? (_reportPossibleCrUseOfAnimatorParams({
  62. error: Error()
  63. }), AnimatorParams) : AnimatorParams)(json.parameters);
  64. this.init(json);
  65. }
  66. /**
  67. * 初始化状态机所有动画状态
  68. */
  69. init(json) {
  70. if (json.states.length <= 0) {
  71. error(`[AnimatorController.init] 状态机json错误`);
  72. return;
  73. }
  74. let defaultState = json.defaultState;
  75. this._anyState = new (_crd && AnimatorState === void 0 ? (_reportPossibleCrUseOfAnimatorState({
  76. error: Error()
  77. }), AnimatorState) : AnimatorState)(json.anyState, this);
  78. for (let i = 0; i < json.states.length; i++) {
  79. let state = new (_crd && AnimatorState === void 0 ? (_reportPossibleCrUseOfAnimatorState({
  80. error: Error()
  81. }), AnimatorState) : AnimatorState)(json.states[i], this);
  82. this._states.set(state.name, state);
  83. }
  84. this.changeState(defaultState);
  85. }
  86. updateState() {
  87. this._curState.checkAndTrans();
  88. if (this._curState !== this._anyState && this._anyState !== null) {
  89. this._anyState.checkAndTrans();
  90. }
  91. }
  92. /**
  93. * 更新状态机逻辑
  94. */
  95. updateAnimator() {
  96. // 重置计数
  97. this._changeCount = 0;
  98. this.updateState(); // 重置动画完成标记
  99. if (this.animComplete && this.animCompleteState.loop) {
  100. this.animComplete = false;
  101. } // 重置autoTrigger
  102. this.params.resetAllAutoTrigger();
  103. }
  104. onAnimationComplete() {
  105. this.animComplete = true;
  106. this.animCompleteState = this._curState; // cc.log(`animation complete: ${this._curState.name}`);
  107. }
  108. /**
  109. * 无视条件直接跳转状态
  110. * @param 状态名
  111. */
  112. play(stateName) {
  113. if (!this._states.has(stateName) || this._curState.name === stateName) {
  114. return;
  115. } // 重置动画完成标记
  116. this.animComplete = false;
  117. this.changeState(stateName);
  118. }
  119. /**
  120. * 切换动画状态
  121. */
  122. changeState(stateName) {
  123. this._changeCount++;
  124. if (this._changeCount > 1000) {
  125. error('[AnimatorController.changeState] error: 状态切换递归调用超过1000次,transition设置可能出错!');
  126. return;
  127. }
  128. if (this._states.has(stateName) && (this._curState === null || this._curState.name !== stateName)) {
  129. let oldState = this._curState;
  130. this._curState = this._states.get(stateName);
  131. this._animator.onStateChange(oldState, this._curState);
  132. this.updateState();
  133. } else {
  134. error(`[AnimatorController.changeState] error state: ${stateName}`);
  135. }
  136. }
  137. });
  138. _cclegacy._RF.pop();
  139. _crd = false;
  140. }
  141. };
  142. });
  143. //# sourceMappingURL=fd0fb4b89f94c1b95d1edde75f9c1d445e7a402f.js.map