e57b803267a903f9e1b0a0c341b2dec3d5f19f37.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. System.register(["cc"], function (_export, _context) {
  2. "use strict";
  3. var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, find, ResolutionPolicy, screen, Size, size, UITransform, view, _dec, _class, _crd, ccclass, property, CHECK_INTERVAL, ResolutionAutoFit;
  4. return {
  5. setters: [function (_cc) {
  6. _cclegacy = _cc.cclegacy;
  7. __checkObsolete__ = _cc.__checkObsolete__;
  8. __checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
  9. _decorator = _cc._decorator;
  10. Component = _cc.Component;
  11. find = _cc.find;
  12. ResolutionPolicy = _cc.ResolutionPolicy;
  13. screen = _cc.screen;
  14. Size = _cc.Size;
  15. size = _cc.size;
  16. UITransform = _cc.UITransform;
  17. view = _cc.view;
  18. }],
  19. execute: function () {
  20. _crd = true;
  21. _cclegacy._RF.push({}, "f237c0rurlJMK37Xb4mkHTf", "ResolutionAutoFit", undefined);
  22. __checkObsolete__(['_decorator', 'Component', 'find', 'Node', 'ResolutionPolicy', 'screen', 'Size', 'size', 'UITransform', 'view']);
  23. ({
  24. ccclass,
  25. property
  26. } = _decorator);
  27. CHECK_INTERVAL = 0.1;
  28. _export("ResolutionAutoFit", ResolutionAutoFit = (_dec = ccclass('ResolutionAutoFit'), _dec(_class = class ResolutionAutoFit extends Component {
  29. constructor() {
  30. super(...arguments);
  31. this._oldSize = size();
  32. this.lastCheckTime = 0;
  33. }
  34. start() {
  35. this.adjustResolutionPolicy();
  36. }
  37. update(deltaTime) {
  38. this.lastCheckTime += deltaTime;
  39. if (this.lastCheckTime < CHECK_INTERVAL) {
  40. return;
  41. }
  42. this.lastCheckTime = 0;
  43. this.adjustResolutionPolicy();
  44. }
  45. adjustResolutionPolicy() {
  46. var winSize = screen.windowSize;
  47. if (!this._oldSize.equals(winSize)) {
  48. var ratio = winSize.width / winSize.height;
  49. var drs = view.getDesignResolutionSize();
  50. var drsRatio = drs.width / drs.height;
  51. var splash = find("Canvas/SpriteSplash");
  52. if (splash) {
  53. splash.getComponent(UITransform).contentSize = new Size(drs.width, drs.height);
  54. }
  55. if (ratio > drsRatio) {
  56. //wider than desgin. fixed height
  57. view.setResolutionPolicy(ResolutionPolicy.FIXED_HEIGHT);
  58. } else {
  59. //
  60. view.setResolutionPolicy(ResolutionPolicy.FIXED_WIDTH);
  61. }
  62. this._oldSize.set(winSize);
  63. }
  64. }
  65. }) || _class));
  66. _cclegacy._RF.pop();
  67. _crd = false;
  68. }
  69. };
  70. });
  71. //# sourceMappingURL=e57b803267a903f9e1b0a0c341b2dec3d5f19f37.js.map