4b2d2de074d1633fcdc3bdfcb7349c4f4f33c15b.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Color, Component, sp, sys, _decorator, _dec, _dec2, _dec3, _class, _class2, _descriptor, _descriptor2, _crd, ccclass, property, SpineView;
  4. function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
  5. function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
  6. function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
  7. return {
  8. setters: [function (_cc) {
  9. _cclegacy = _cc.cclegacy;
  10. __checkObsolete__ = _cc.__checkObsolete__;
  11. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  12. Color = _cc.Color;
  13. Component = _cc.Component;
  14. sp = _cc.sp;
  15. sys = _cc.sys;
  16. _decorator = _cc._decorator;
  17. }],
  18. execute: function () {
  19. _crd = true;
  20. _cclegacy._RF.push({}, "ce889T62SpI8ot39/O0nFrT", "SpineView", undefined);
  21. __checkObsolete__(['Color', 'Component', 'sp', 'sys', '_decorator']);
  22. ({
  23. ccclass,
  24. property
  25. } = _decorator);
  26. /**
  27. * spine动画表现管理
  28. * @author
  29. *
  30. */
  31. _export("default", SpineView = (_dec = ccclass('SpineView'), _dec2 = property({
  32. displayName: '待机'
  33. }), _dec3 = property({
  34. type: sp.Skeleton,
  35. tooltip: '角色动画'
  36. }), _dec(_class = (_class2 = class SpineView extends Component {
  37. constructor(...args) {
  38. super(...args);
  39. this.skin = "default";
  40. _initializerDefineProperty(this, "idle", _descriptor, this);
  41. _initializerDefineProperty(this, "spine", _descriptor2, this);
  42. this.cur = null;
  43. this.OnComp = void 0;
  44. this.resetColor = Color.WHITE;
  45. }
  46. onLoad() {
  47. //console.log("111111111111");
  48. //this.spine.enableBatch=false;
  49. if (sys.isNative) {
  50. //原生共享模式有bug
  51. this.spine.setAnimationCacheMode(sp.AnimationCacheMode.REALTIME);
  52. this.spine.clearTracks(); //清理所有播放队列的动画
  53. } //this.SetSkin(this.skin);
  54. }
  55. start() {
  56. this.DoAnimation(this.idle, true);
  57. this.spine.setCompleteListener(function () {
  58. if (this.OnComp) this.OnComp();
  59. }.bind(this));
  60. }
  61. onBeforeRemove() {
  62. this.spine.setCompleteListener(null);
  63. }
  64. Dispos() {
  65. this.ResetColor();
  66. this.OnComp = null; //this.spine.setCompleteListener(null);
  67. }
  68. SetSkin(skin) {
  69. this.spine.setSkin(skin);
  70. }
  71. DoAnimation(animation, loop = true, track = 0, force = false) {
  72. if (force) {
  73. this.spine.setAnimation(track, animation, loop);
  74. return;
  75. }
  76. if (this.cur == animation) return;
  77. this.spine.setAnimation(track, animation, loop);
  78. }
  79. /**设置是否暂停 */
  80. SetPaused(paused) {
  81. this.spine.paused = paused;
  82. }
  83. /**获取是否暂停 */
  84. GetPaused() {
  85. return this.spine.paused;
  86. }
  87. CheckPaused(paused) {
  88. if (this.spine.paused != paused) this.spine.paused = paused;
  89. }
  90. /** 闪色表现 Color.RED 0.1*/
  91. Flash(color, time) {
  92. if (this.spine.color != color) {
  93. this.spine.color = color;
  94. this.unscheduleAllCallbacks();
  95. this.scheduleOnce(() => {
  96. this.spine.color = this.resetColor;
  97. }, time);
  98. }
  99. }
  100. ChangeMagenta() {
  101. this.ChangeColor(Color.MAGENTA);
  102. }
  103. ChangeGreen() {
  104. this.ChangeColor(Color.GREEN);
  105. }
  106. ChangeGray() {
  107. this.ChangeColor(Color.GRAY);
  108. }
  109. ChangeRed() {
  110. this.ChangeColor(Color.RED);
  111. }
  112. ChangeCyan() {
  113. this.ChangeColor(Color.CYAN);
  114. }
  115. ChangeBlack() {
  116. this.ChangeColor(Color.BLACK);
  117. }
  118. ChangeBule() {
  119. this.ChangeColor(Color.BLUE);
  120. }
  121. ChangeYellow() {
  122. this.ChangeColor(Color.YELLOW);
  123. } //
  124. /** 变色表现 Color.RED 0.1*/
  125. ChangeColor(color) {
  126. this.resetColor = color;
  127. if (this.spine.color != this.resetColor) {
  128. this.spine.color = this.resetColor;
  129. }
  130. }
  131. ResetColor() {
  132. this.resetColor = Color.WHITE;
  133. if (this.spine.color != this.resetColor) {
  134. this.spine.color = this.resetColor;
  135. }
  136. }
  137. /**
  138. * 缩放动画播放速率
  139. * @override
  140. * @param scale 缩放倍率
  141. */
  142. scaleTime(scale) {
  143. if (scale > 0) this.spine.timeScale = scale;
  144. }
  145. getBone(name) {
  146. var bone = this.spine.findBone(name);
  147. return bone;
  148. }
  149. /**
  150. * 换装
  151. * @param slotName 插槽名字
  152. * @param attachmentName 元素名字
  153. */
  154. changeEquipment(slotName, attachmentName = null) {
  155. const slot = this.spine.findSlot(slotName);
  156. if (slot) {
  157. if (attachmentName) {
  158. const attachment = this.spine.getAttachment(slotName, attachmentName);
  159. slot.setAttachment(attachment);
  160. } else {
  161. slot.setAttachment(null);
  162. }
  163. }
  164. }
  165. /**换装
  166. * @param skinName 要替换的部件皮肤名称
  167. * @param slotName 要替换的部件的插槽名称
  168. * @param targetAttaName Spine中皮肤占位符的名字
  169. */
  170. changeSlot(skinName, slotName, targetAttaName) {
  171. //查找局部皮肤
  172. let skeletonData = this.spine.skeletonData.getRuntimeData();
  173. let targetSkin = skeletonData.findSkin(skinName); //查找局部皮肤下的插槽与附件
  174. let targetSkinSlotIndex = skeletonData.findSlotIndex(slotName);
  175. let atta = targetSkin.getAttachment(targetSkinSlotIndex, targetAttaName); //查找全身皮肤下的插槽
  176. let curSlot = this.spine.findSlot(slotName); //替换全身皮肤插槽的附件
  177. curSlot && curSlot.setAttachment(atta);
  178. }
  179. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "idle", [_dec2], {
  180. configurable: true,
  181. enumerable: true,
  182. writable: true,
  183. initializer: function () {
  184. return "";
  185. }
  186. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "spine", [_dec3], {
  187. configurable: true,
  188. enumerable: true,
  189. writable: true,
  190. initializer: function () {
  191. return null;
  192. }
  193. })), _class2)) || _class));
  194. _cclegacy._RF.pop();
  195. _crd = false;
  196. }
  197. };
  198. });
  199. //# sourceMappingURL=4b2d2de074d1633fcdc3bdfcb7349c4f4f33c15b.js.map