2cfd29187419e6cd43035f6143fb6e282773af7c.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. System.register(["__unresolved_0", "cc", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, sp, AnimatorBase, _dec, _dec2, _dec3, _class, _crd, ccclass, property, requireComponent, disallowMultiple, menu, help, AnimatorSpine;
  4. function _reportPossibleCrUseOfAnimatorSpineSecondary(extras) {
  5. _reporterNs.report("AnimatorSpineSecondary", "./AnimatorSpineSecondary", _context.meta, extras);
  6. }
  7. function _reportPossibleCrUseOfAnimatorBase(extras) {
  8. _reporterNs.report("AnimatorBase", "./core/AnimatorBase", _context.meta, extras);
  9. }
  10. function _reportPossibleCrUseOfAnimationPlayer(extras) {
  11. _reporterNs.report("AnimationPlayer", "./core/AnimatorBase", _context.meta, extras);
  12. }
  13. function _reportPossibleCrUseOfAnimatorStateLogic(extras) {
  14. _reporterNs.report("AnimatorStateLogic", "./core/AnimatorStateLogic", _context.meta, extras);
  15. }
  16. return {
  17. setters: [function (_unresolved_) {
  18. _reporterNs = _unresolved_;
  19. }, function (_cc) {
  20. _cclegacy = _cc.cclegacy;
  21. __checkObsolete__ = _cc.__checkObsolete__;
  22. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  23. _decorator = _cc._decorator;
  24. sp = _cc.sp;
  25. }, function (_unresolved_2) {
  26. AnimatorBase = _unresolved_2.default;
  27. }],
  28. execute: function () {
  29. _crd = true;
  30. _cclegacy._RF.push({}, "7fde8yJEfxMMqzjg+V4UVkT", "AnimatorSpine", undefined);
  31. __checkObsolete__(['_decorator', 'sp']);
  32. ({
  33. ccclass,
  34. property,
  35. requireComponent,
  36. disallowMultiple,
  37. menu,
  38. help
  39. } = _decorator);
  40. /**
  41. * Spine状态机组件(主状态机),trackIndex为0
  42. */
  43. _export("default", AnimatorSpine = (_dec = requireComponent(sp.Skeleton), _dec2 = menu('OopsFramework/Animator/AnimatorSpine(Spine 状态机)'), _dec3 = help('https://gitee.com/dgflash/oops-framework/wikis/pages?sort_id=12036279&doc_id=2873565'), ccclass(_class = disallowMultiple(_class = _dec(_class = _dec2(_class = _dec3(_class = class AnimatorSpine extends (_crd && AnimatorBase === void 0 ? (_reportPossibleCrUseOfAnimatorBase({
  44. error: Error()
  45. }), AnimatorBase) : AnimatorBase) {
  46. constructor() {
  47. super(...arguments);
  48. /** spine组件 */
  49. this._spine = null;
  50. /** 动画完成的回调 */
  51. this._completeListenerMap = new Map();
  52. /** 次状态机注册的回调 */
  53. this._secondaryListenerMap = new Map();
  54. }
  55. start() {
  56. if (!this.PlayOnStart || this._hasInit) {
  57. return;
  58. }
  59. this._hasInit = true;
  60. this._spine = this.getComponent(sp.Skeleton);
  61. this._spine.setEventListener(this.onSpineEvent.bind(this));
  62. this._spine.setCompleteListener(this.onSpineComplete.bind(this));
  63. if (this.AssetRawUrl !== null) {
  64. this.initJson(this.AssetRawUrl.json);
  65. }
  66. }
  67. /**
  68. * 手动初始化状态机,可传入0-3个参数,类型如下
  69. * - onStateChangeCall 状态切换时的回调
  70. * - stateLogicMap 各个状态逻辑控制
  71. * - animationPlayer 自定义动画控制
  72. * @override
  73. */
  74. onInit() {
  75. if (this.PlayOnStart || this._hasInit) {
  76. return;
  77. }
  78. this._hasInit = true;
  79. this.initArgs(...arguments);
  80. this._spine = this.getComponent(sp.Skeleton);
  81. this._spine.setEventListener(this.onSpineEvent.bind(this));
  82. this._spine.setCompleteListener(this.onSpineComplete.bind(this));
  83. if (this.AssetRawUrl !== null) {
  84. this.initJson(this.AssetRawUrl.json);
  85. }
  86. }
  87. /** ---------- 后续扩展代码 开始 ---------- */
  88. getBone(name) {
  89. var bone = this._spine.findBone(name);
  90. return bone;
  91. }
  92. onSpineEvent(trackEntry, event) {
  93. var _this$_animationPlaye;
  94. var animationName = trackEntry.animation ? event.data.name : "";
  95. (_this$_animationPlaye = this._animationPlayer) == null || _this$_animationPlaye.onFrameEventCallback(animationName, this);
  96. }
  97. /** ---------- 后续扩展代码 结束 ---------- */
  98. onSpineComplete(entry) {
  99. entry.trackIndex === 0 && this.onAnimFinished();
  100. this._completeListenerMap.forEach((target, cb) => {
  101. target ? cb.call(target, entry) : cb(entry);
  102. });
  103. this._secondaryListenerMap.forEach((target, cb) => {
  104. entry.trackIndex === target.TrackIndex && cb.call(target, entry);
  105. });
  106. }
  107. /**
  108. * 播放动画
  109. * @override
  110. * @param animName 动画名
  111. * @param loop 是否循环播放
  112. */
  113. playAnimation(animName, loop) {
  114. if (animName) {
  115. this._spine.setAnimation(0, animName, loop);
  116. } else {
  117. this._spine.clearTrack(0);
  118. }
  119. }
  120. /**
  121. * 缩放动画播放速率
  122. * @override
  123. * @param scale 缩放倍率
  124. */
  125. scaleTime(scale) {
  126. if (scale > 0) this._spine.timeScale = scale;
  127. }
  128. /**
  129. * 注册次状态机动画结束的回调(状态机内部方法,不能由外部直接调用)
  130. */
  131. addSecondaryListener(cb, target) {
  132. this._secondaryListenerMap.set(cb, target);
  133. }
  134. /**
  135. * 注册动画完成时的监听
  136. * @param cb 回调
  137. * @param target 调用回调的this对象
  138. */
  139. addCompleteListener(cb, target) {
  140. if (target === void 0) {
  141. target = null;
  142. }
  143. if (this._completeListenerMap.has(cb)) {
  144. return;
  145. }
  146. this._completeListenerMap.set(cb, target);
  147. }
  148. /**
  149. * 注销动画完成的监听
  150. * @param cb 回调
  151. */
  152. removeCompleteListener(cb) {
  153. this._completeListenerMap.delete(cb);
  154. }
  155. /**
  156. * 清空动画完成的监听
  157. */
  158. clearCompleteListener() {
  159. this._completeListenerMap.clear;
  160. }
  161. }) || _class) || _class) || _class) || _class) || _class));
  162. _cclegacy._RF.pop();
  163. _crd = false;
  164. }
  165. };
  166. });
  167. //# sourceMappingURL=2cfd29187419e6cd43035f6143fb6e282773af7c.js.map