1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- var t = require;
- var e = module;
- var i = exports;
- e =
- (this && this.__decorate) ||
- function(t, e, i, s) {
- var o,
- a = arguments.length,
- n = a < 3 ? e : null === s ? (s = Object.getOwnPropertyDescriptor(e, i)) : s;
- if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, i, s);
- else
- for (var r = t.length - 1; 0 <= r; r--)
- (o = t[r]) && (n = (a < 3 ? o(n) : 3 < a ? o(e, i, n) : o(e, i)) || n);
- return 3 < a && n && Object.defineProperty(e, i, n), n;
- };
- Object.defineProperty(i, "__esModule", { value: !0 });
- const s = t("App"),
- o = "AutoReleaseImg",
- { ccclass: a, property: n, menu: r } = cc._decorator;
- t = class extends cc.Sprite {
- constructor() {
- super(...arguments),
- (this._source = ""),
- (this.imgState = 0),
- (this._spriteFrame = null),
- (this.isNeedDestory = !1),
- (this.isReleaseUnable = !1);
- }
- set source(i) {
- i
- ?
- ((this.spriteFrame = i),
- Editor.assetdb.queryMetaInfoByUuid(i._uuid, (t, e) => {
- if (t) cc.error(t);
- else {
- let t = e.assetUrl;
- t.startsWith("db://assets/resources") ?
- ((this.spriteFrame = i),
- (t = t.replace("db://assets/resources/", "")),
- (this._source = t.slice(0, t.lastIndexOf("."))),
- Editor.log(this._source)) :
- cc.error("只允许放置resources文件夹里面的图片");
- }
- })) :
- ((this.spriteFrame = null), (this._source = ""));
- }
- get source() {
- return this._spriteFrame;
- }
- onLoad() {
- this.isNeedDestory || this.parseSource();
- }
- onImgDestory() {
- this.spriteFrame &&
- (s.default.ResRecycle.decRefByUrl(this._source, o), (this.spriteFrame = null), (this.imgState = 0));
- }
- onEnable() {
- super.onEnable(), this.isReleaseUnable && this.parseSource();
- }
- onDisable() {
- super.onDisable(), this.isReleaseUnable && this.onImgDestory();
- }
- onDestroy() {
- this.onImgDestory();
- }
- parseSource() {
- if (0 == this.imgState) {
- let i = this._source;
- (this.imgState = 1),
- cc.resources.load(i, cc.SpriteFrame, (t, e) => {
- if (t)(this.imgState = 0), Log.error(`\u56fe\u7247\u4e0d\u5b58\u5728:${i}`, t);
- else if ((s.default.ResRecycle.addUrl(i, o), this.isValid)) {
- if (this.isReleaseUnable && !this.node.activeInHierarchy)
- return (this.imgState = 0), void s.default.ResRecycle.decRefByUrl(i, o);
- (this.imgState = 2), (this.spriteFrame = e);
- } else s.default.ResRecycle.decRefByUrl(i, o);
- });
- }
- }
- };
- e([n()], t.prototype, "_source", void 0),
- e([n({ type: cc.SpriteFrame, editorOnly: !0, override: !0 })], t.prototype, "_spriteFrame", void 0),
- e([n({ type: cc.SpriteFrame, override: !0 })], t.prototype, "source", null),
- e([n({})], t.prototype, "isReleaseUnable", void 0),
- (t = e([a], t)),
- (i.default = t);
|