b96f08257d66ee9cf4f2a31191913892df6c3feb.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. System.register(["__unresolved_0", "cc", "cc/env", "__unresolved_1"], function (_export, _context) {
  2. "use strict";
  3. var _reporterNs, _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, Enum, Sprite, UITransform, v3, Widget, _decorator, EDITOR, Adapter, _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _crd, ccclass, property, executeInEditMode, menu, SpriteScaleType, SpriteAlignType, AdapterSprite;
  4. 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; }
  5. function _reportPossibleCrUseOfAdapter(extras) {
  6. _reporterNs.report("Adapter", "./Adapter", _context.meta, extras);
  7. }
  8. return {
  9. setters: [function (_unresolved_) {
  10. _reporterNs = _unresolved_;
  11. }, function (_cc) {
  12. _cclegacy = _cc.cclegacy;
  13. __checkObsolete__ = _cc.__checkObsolete__;
  14. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  15. Enum = _cc.Enum;
  16. Sprite = _cc.Sprite;
  17. UITransform = _cc.UITransform;
  18. v3 = _cc.v3;
  19. Widget = _cc.Widget;
  20. _decorator = _cc._decorator;
  21. }, function (_ccEnv) {
  22. EDITOR = _ccEnv.EDITOR;
  23. }, function (_unresolved_2) {
  24. Adapter = _unresolved_2.Adapter;
  25. }],
  26. execute: function () {
  27. _crd = true;
  28. _cclegacy._RF.push({}, "eeb87KiuDBE4KodowbfprPJ", "AdapterSprite", undefined);
  29. __checkObsolete__(['Enum', 'Sprite', 'UITransform', 'v3', 'Widget', '_decorator']);
  30. ({
  31. ccclass,
  32. property,
  33. executeInEditMode,
  34. menu
  35. } = _decorator);
  36. /**
  37. * 缩放方式
  38. */
  39. _export("SpriteScaleType", SpriteScaleType = /*#__PURE__*/function (SpriteScaleType) {
  40. SpriteScaleType[SpriteScaleType["FILL"] = 0] = "FILL";
  41. SpriteScaleType[SpriteScaleType["SUIT"] = 1] = "SUIT";
  42. return SpriteScaleType;
  43. }({}));
  44. /**
  45. * 对齐方式
  46. */
  47. _export("SpriteAlignType", SpriteAlignType = /*#__PURE__*/function (SpriteAlignType) {
  48. SpriteAlignType[SpriteAlignType["LEFT"] = 0] = "LEFT";
  49. SpriteAlignType[SpriteAlignType["TOP"] = 1] = "TOP";
  50. SpriteAlignType[SpriteAlignType["RIGHT"] = 2] = "RIGHT";
  51. SpriteAlignType[SpriteAlignType["BOTTOM"] = 3] = "BOTTOM";
  52. SpriteAlignType[SpriteAlignType["CENTER"] = 4] = "CENTER";
  53. return SpriteAlignType;
  54. }({}));
  55. /**
  56. * Sprite 适配组件
  57. *
  58. * @author caizhitao
  59. * @created 2020-12-27 21:22:43
  60. */
  61. _export("default", AdapterSprite = (_dec = ccclass("AdapterSprite"), _dec2 = executeInEditMode(true), _dec3 = menu("Quick适配组件/AdapterSprite"), _dec4 = property({
  62. type: Enum(SpriteScaleType),
  63. tooltip: "\u7F29\u653E\u7C7B\u578B:\n -FILL: \u7F29\u653E\u5230\u586B\u6EE1\u7236\u8282\u70B9\uFF08\u5982\u679C\u7236\u8282\u70B9\u6709\u88C1\u526A\uFF0C\u56FE\u50CF\u53EF\u80FD\u4F1A\u88AB\u88C1\u526A\uFF0C\u8282\u70B9\u53EF\u80FD\u4F1A\u8D85\u51FA\u7236\u8282\u70B9\uFF09\n -SUIT: \u7F29\u653E\u5230\u521A\u597D\u5728\u7236\u8282\u70B9\u5185\u90E8\u6700\u5927\u5316\u663E\u793A\uFF08\u56FE\u50CF\u4F1A\u5B8C\u6574\u663E\u793A\uFF0C\u4F46\u7236\u8282\u70B9\u4E0A\u4E0B\u6216\u8005\u5DE6\u53F3\u53EF\u80FD\u4F1A\u7559\u7A7A\uFF09"
  64. }), _dec5 = property({
  65. type: Enum(SpriteAlignType),
  66. tooltip: "\u9F50\u65B9\u5F0F\u7C7B\u578B:\n -LEFT: \u7F29\u653E\u540E\u9760\u5DE6\u5BF9\u9F50\n -TOP: \u7F29\u653E\u540E\u9760\u4E0A\u5BF9\u9F50\n -RIGHT: \u7F29\u653E\u540E\u9760\u53F3\u5BF9\u9F50\n -BOTTOM: \u7F29\u653E\u540E\u9760\u4E0B\u5BF9\u9F50\n -CENTER: \u7F29\u653E\u540E\u5C45\u4E2D\u5BF9\u9F50"
  67. }), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class AdapterSprite extends (_crd && Adapter === void 0 ? (_reportPossibleCrUseOfAdapter({
  68. error: Error()
  69. }), Adapter) : Adapter) {
  70. constructor() {
  71. super(...arguments);
  72. this._scaleType = SpriteScaleType.SUIT;
  73. this._alignType = SpriteAlignType.CENTER;
  74. this._sprite = null;
  75. }
  76. get scaleType() {
  77. return this._scaleType;
  78. }
  79. set scaleType(value) {
  80. this._scaleType = value;
  81. if (EDITOR) {
  82. this.updateSprite(this._scaleType, this.alignType);
  83. }
  84. }
  85. get alignType() {
  86. return this._alignType;
  87. }
  88. set alignType(value) {
  89. this._alignType = value;
  90. if (EDITOR) {
  91. this.updateSprite(this._scaleType, this._alignType);
  92. }
  93. }
  94. onLoad() {
  95. this._sprite = this.node.getComponent(Sprite);
  96. }
  97. start() {
  98. this.updateSprite(this.scaleType, this.alignType);
  99. }
  100. onChangeSize() {
  101. this.updateSprite(this.scaleType, this.alignType);
  102. }
  103. updateSprite(scaleType, alignType) {
  104. var _this$node$parent;
  105. if (!this._sprite || !this._sprite.enabled || !this._sprite.spriteFrame) {
  106. return;
  107. }
  108. var widget = (_this$node$parent = this.node.parent) == null ? void 0 : _this$node$parent.getComponent(Widget);
  109. if (widget) {
  110. widget.updateAlignment();
  111. }
  112. this.width = this._sprite.spriteFrame.rect.width;
  113. this.height = this._sprite.spriteFrame.rect.height;
  114. var trans = this.parentTrans;
  115. if (this.width / this.height > trans.width / trans.height) {
  116. // 设计分辨率宽高比大于显示分辨率
  117. if (scaleType == SpriteScaleType.SUIT) {
  118. var scale = trans.width / this.width;
  119. this.node.scale = v3(scale, scale);
  120. } else if (scaleType == SpriteScaleType.FILL) {
  121. var _scale = trans.height / this.height;
  122. this.node.scale = v3(_scale, _scale);
  123. }
  124. } else {
  125. // 设计分辨率宽高比小于显示分辨率
  126. if (scaleType == SpriteScaleType.SUIT) {
  127. var _scale2 = trans.height / this.height;
  128. this.node.scale = v3(_scale2, _scale2);
  129. } else if (scaleType == SpriteScaleType.FILL) {
  130. var _scale3 = trans.width / this.width;
  131. this.node.scale = v3(_scale3, _scale3);
  132. }
  133. }
  134. switch (alignType) {
  135. case SpriteAlignType.CENTER:
  136. this.node.setPosition(v3());
  137. break;
  138. case SpriteAlignType.LEFT:
  139. this.node.setPosition(v3(-0.5 * (trans.width - this.width * this.node.scale.x), 0));
  140. break;
  141. case SpriteAlignType.RIGHT:
  142. this.node.setPosition(v3(0.5 * (trans.width - this.width * this.node.scale.x), 0));
  143. break;
  144. case SpriteAlignType.TOP:
  145. this.node.setPosition(v3(0, 0.5 * (trans.height - this.height * this.node.scale.x)));
  146. break;
  147. case SpriteAlignType.BOTTOM:
  148. this.node.setPosition(v3(0, -0.5 * (trans.height - this.height * this.node.scale.x)));
  149. break;
  150. }
  151. this.doOnAdapterComplete();
  152. }
  153. get parentTrans() {
  154. var _this$node$parent2;
  155. return (_this$node$parent2 = this.node.parent) == null ? void 0 : _this$node$parent2.getComponent(UITransform);
  156. }
  157. }, (_applyDecoratedDescriptor(_class2.prototype, "scaleType", [_dec4], Object.getOwnPropertyDescriptor(_class2.prototype, "scaleType"), _class2.prototype), _applyDecoratedDescriptor(_class2.prototype, "alignType", [_dec5], Object.getOwnPropertyDescriptor(_class2.prototype, "alignType"), _class2.prototype)), _class2)) || _class) || _class) || _class));
  158. _cclegacy._RF.pop();
  159. _crd = false;
  160. }
  161. };
  162. });
  163. //# sourceMappingURL=b96f08257d66ee9cf4f2a31191913892df6c3feb.js.map