init
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
System.register(["cc"], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var _cclegacy, __checkObsolete__, __checkObsoleteInNamespace__, _decorator, Component, _dec, _class, _class2, _crd, ccclass, property, SingletonBase;
|
||||
|
||||
return {
|
||||
setters: [function (_cc) {
|
||||
_cclegacy = _cc.cclegacy;
|
||||
__checkObsolete__ = _cc.__checkObsolete__;
|
||||
__checkObsoleteInNamespace__ = _cc.__checkObsoleteInNamespace__;
|
||||
_decorator = _cc._decorator;
|
||||
Component = _cc.Component;
|
||||
}],
|
||||
execute: function () {
|
||||
_crd = true;
|
||||
|
||||
_cclegacy._RF.push({}, "983a7Fa7u9CALdO3YvO3QLZ", "SingletonBase", undefined);
|
||||
|
||||
__checkObsolete__(['_decorator', 'Component']);
|
||||
|
||||
({
|
||||
ccclass,
|
||||
property
|
||||
} = _decorator);
|
||||
|
||||
_export("SingletonBase", SingletonBase = (_dec = ccclass('SingletonBase'), _dec(_class = (_class2 = class SingletonBase extends Component {
|
||||
static getInstance() {
|
||||
if (this._instance === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this._instance;
|
||||
}
|
||||
|
||||
onLoad() {
|
||||
if (this.constructor._instance) {
|
||||
this.node.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
this.constructor._instance = this;
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
if (this.constructor._instance === this) {
|
||||
this.constructor._instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
}, _class2._instance = null, _class2)) || _class));
|
||||
|
||||
_cclegacy._RF.pop();
|
||||
|
||||
_crd = false;
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=d2fe8f613eaa9369920a8fa74ab19eccb4860b54.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["file:///D:/Users/admin/Alien_Sniper/assets/scripts/framework/SingletonBase.ts"],"names":["_decorator","Component","ccclass","property","SingletonBase","getInstance","_instance","onLoad","constructor","node","destroy","onDestroy"],"mappings":";;;;;;;;;;AAASA,MAAAA,U,OAAAA,U;AAAYC,MAAAA,S,OAAAA,S;;;;;;;;;OACf;AAAEC,QAAAA,OAAF;AAAWC,QAAAA;AAAX,O,GAAwBH,U;;+BAGRI,a,WADrBF,OAAO,CAAC,eAAD,C,2BAAR,MACsBE,aADtB,SACiEH,SADjE,CAC2E;AAG9C,eAAXI,WAAW,GAA4C;AACjE,cAAK,IAAD,CAAcC,SAAd,KAA4B,IAAhC,EAAsC;AAClC,mBAAO,IAAP;AACH;;AACD,iBAAQ,IAAD,CAAcA,SAArB;AACH;;AAESC,QAAAA,MAAM,GAAS;AACrB,cAAK,KAAKC,WAAN,CAA0BF,SAA9B,EAAyC;AACrC,iBAAKG,IAAL,CAAUC,OAAV;AACA;AACH;;AACA,eAAKF,WAAN,CAA0BF,SAA1B,GAAsC,IAAtC;AACH;;AAESK,QAAAA,SAAS,GAAS;AACxB,cAAK,KAAKH,WAAN,CAA0BF,SAA1B,KAAwC,IAA5C,EAAkD;AAC7C,iBAAKE,WAAN,CAA0BF,SAA1B,GAAsC,IAAtC;AACH;AACJ;;AAtBsE,O,UACxDA,S,GAAiB,I","sourcesContent":["import { _decorator, Component } from 'cc';\r\nconst { ccclass, property } = _decorator;\r\n\r\n@ccclass('SingletonBase')\r\nexport abstract class SingletonBase<T extends Component> extends Component {\r\n private static _instance: any = null;\r\n\r\n public static getInstance<T extends Component>(this: new () => T): T {\r\n if ((this as any)._instance === null) {\r\n return null\r\n }\r\n return (this as any)._instance;\r\n }\r\n\r\n protected onLoad(): void {\r\n if ((this.constructor as any)._instance) {\r\n this.node.destroy();\r\n return;\r\n }\r\n (this.constructor as any)._instance = this;\r\n }\r\n\r\n protected onDestroy(): void {\r\n if ((this.constructor as any)._instance === this) {\r\n (this.constructor as any)._instance = null;\r\n }\r\n }\r\n}"]}
|
||||
Reference in New Issue
Block a user