20712297188dd3bbe9fb3acc1799edea45dda86b.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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() {
  38. super(...arguments);
  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, track, force) {
  72. if (loop === void 0) {
  73. loop = true;
  74. }
  75. if (track === void 0) {
  76. track = 0;
  77. }
  78. if (force === void 0) {
  79. force = false;
  80. }
  81. if (force) {
  82. this.spine.setAnimation(track, animation, loop);
  83. return;
  84. }
  85. if (this.cur == animation) return;
  86. this.spine.setAnimation(track, animation, loop);
  87. }
  88. /**设置是否暂停 */
  89. SetPaused(paused) {
  90. this.spine.paused = paused;
  91. }
  92. /**获取是否暂停 */
  93. GetPaused() {
  94. return this.spine.paused;
  95. }
  96. CheckPaused(paused) {
  97. if (this.spine.paused != paused) this.spine.paused = paused;
  98. }
  99. /** 闪色表现 Color.RED 0.1*/
  100. Flash(color, time) {
  101. if (this.spine.color != color) {
  102. this.spine.color = color;
  103. this.unscheduleAllCallbacks();
  104. this.scheduleOnce(() => {
  105. this.spine.color = this.resetColor;
  106. }, time);
  107. }
  108. }
  109. ChangeMagenta() {
  110. this.ChangeColor(Color.MAGENTA);
  111. }
  112. ChangeGreen() {
  113. this.ChangeColor(Color.GREEN);
  114. }
  115. ChangeGray() {
  116. this.ChangeColor(Color.GRAY);
  117. }
  118. ChangeRed() {
  119. this.ChangeColor(Color.RED);
  120. }
  121. ChangeCyan() {
  122. this.ChangeColor(Color.CYAN);
  123. }
  124. ChangeBlack() {
  125. this.ChangeColor(Color.BLACK);
  126. }
  127. ChangeBule() {
  128. this.ChangeColor(Color.BLUE);
  129. }
  130. ChangeYellow() {
  131. this.ChangeColor(Color.YELLOW);
  132. } //
  133. /** 变色表现 Color.RED 0.1*/
  134. ChangeColor(color) {
  135. this.resetColor = color;
  136. if (this.spine.color != this.resetColor) {
  137. this.spine.color = this.resetColor;
  138. }
  139. }
  140. ResetColor() {
  141. this.resetColor = Color.WHITE;
  142. if (this.spine.color != this.resetColor) {
  143. this.spine.color = this.resetColor;
  144. }
  145. }
  146. /**
  147. * 缩放动画播放速率
  148. * @override
  149. * @param scale 缩放倍率
  150. */
  151. scaleTime(scale) {
  152. if (scale > 0) this.spine.timeScale = scale;
  153. }
  154. getBone(name) {
  155. var bone = this.spine.findBone(name);
  156. return bone;
  157. }
  158. /**
  159. * 换装
  160. * @param slotName 插槽名字
  161. * @param attachmentName 元素名字
  162. */
  163. changeEquipment(slotName, attachmentName) {
  164. if (attachmentName === void 0) {
  165. attachmentName = null;
  166. }
  167. var slot = this.spine.findSlot(slotName);
  168. if (slot) {
  169. if (attachmentName) {
  170. var attachment = this.spine.getAttachment(slotName, attachmentName);
  171. slot.setAttachment(attachment);
  172. } else {
  173. slot.setAttachment(null);
  174. }
  175. }
  176. }
  177. /**换装
  178. * @param skinName 要替换的部件皮肤名称
  179. * @param slotName 要替换的部件的插槽名称
  180. * @param targetAttaName Spine中皮肤占位符的名字
  181. */
  182. changeSlot(skinName, slotName, targetAttaName) {
  183. //查找局部皮肤
  184. var skeletonData = this.spine.skeletonData.getRuntimeData();
  185. var targetSkin = skeletonData.findSkin(skinName); //查找局部皮肤下的插槽与附件
  186. var targetSkinSlotIndex = skeletonData.findSlotIndex(slotName);
  187. var atta = targetSkin.getAttachment(targetSkinSlotIndex, targetAttaName); //查找全身皮肤下的插槽
  188. var curSlot = this.spine.findSlot(slotName); //替换全身皮肤插槽的附件
  189. curSlot && curSlot.setAttachment(atta);
  190. }
  191. }, (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "idle", [_dec2], {
  192. configurable: true,
  193. enumerable: true,
  194. writable: true,
  195. initializer: function initializer() {
  196. return "";
  197. }
  198. }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "spine", [_dec3], {
  199. configurable: true,
  200. enumerable: true,
  201. writable: true,
  202. initializer: function initializer() {
  203. return null;
  204. }
  205. })), _class2)) || _class));
  206. _cclegacy._RF.pop();
  207. _crd = false;
  208. }
  209. };
  210. });
  211. //# sourceMappingURL=20712297188dd3bbe9fb3acc1799edea45dda86b.js.map