ChangeScaleBySize.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. var s =
  5. (this && this.__decorate) ||
  6. function(t, e, i, s) {
  7. var o,
  8. a = arguments.length,
  9. n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
  10. if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
  11. else
  12. for (var r = t.length - 1; 0 <= r; r--)
  13. (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
  14. return 3 < a && n && Object.defineProperty(e, i, n), n;
  15. };
  16. Object.defineProperty(i, "__esModule", { value: !0 });
  17. const { ccclass: o, property: a, executeInEditMode: n, menu: r } = cc._decorator;
  18. e = class extends cc.Component {
  19. constructor() {
  20. super(...arguments), (this._maxSize = 100);
  21. }
  22. set maxSize(t) {
  23. (this._maxSize = t), this.onSizeChange();
  24. }
  25. get maxSize() {
  26. return this._maxSize;
  27. }
  28. onLoad() {
  29. this.node.on(cc.Node.EventType.SIZE_CHANGED, this.onSizeChange, this), this.onSizeChange();
  30. }
  31. onSizeChange() {
  32. var t;
  33. this.node.width > this._maxSize || this.node.height > this._maxSize ?
  34. ((t =
  35. this.node.width > this.node.height ?
  36. this._maxSize / this.node.width :
  37. this._maxSize / this.node.height),
  38. (this.node.scale = t)) :
  39. (this.node.scale = 1);
  40. }
  41. };
  42. s([a], e.prototype, "_maxSize", void 0),
  43. s([a({})], e.prototype, "maxSize", null),
  44. (e = s([o, n], e)),
  45. (i.default = e);