core-egret.IHashObject

egret.IHashObject 使用範例


class Main extends eui.UILayer {

    protected createChildren(): void {
        super.createChildren();
        egret.lifecycle.onPause = () => egret.ticker.pause();
        egret.lifecycle.onResume = () => egret.ticker.resume();
        egret.registerImplementation('eui.IAssetAdapter', new AssetAdapter());
        egret.registerImplementation('eui.IThemeAdapter', new ThemeAdapter());
        this.runGame();
    }

    private async loadResource() {
        let loadingView = this.stage.addChild(new LoadingUI()) as LoadingUI;
        await RES.loadConfig('resource/default.res.json', 'resource/');
        await new Promise(resolve => new eui.Theme('resource/default.thm.json', this.stage).once(eui.UIEvent.COMPLETE, resolve, this));
        await RES.loadGroup('preload', 0, loadingView);
        this.stage.removeChild(loadingView);
    }

    private async runGame() {
        await this.loadResource();
        // --- Edwin 給你最乾淨的程式碼, 從這行以下開始寫喔 ---

        egret.log(egret.$hashCount); // 204, 最新編號將是 204 表示目前有 203 個物件在內存運用
        const plugin = new MyPluginObject; // 此時物件 hashCode 是 204, 最新編號是 205
        const plugin2 = new MyPluginObject; // 此時物件 hashCode 是 205, 最新編號是 206
        egret.log(egret.$hashCount); // 206
        console.log(plugin.hashCode); // 204
        console.log(plugin2.hashCode); // 205

    }

}

// 讓自定義物件也列入 hashCount 總數計算, implements egret.IHashObject 可有可無, 因為 egret.HashObject 已經實作 hashCode getter
class MyPluginObject extends egret.HashObject implements egret.IHashObject{}

spacer

沒有留言:

張貼留言