class GameUIScript extends paper.Behaviour
{
      onStart() {
            //egret3d.Egret2DRenderer 可以添加egret2D的显示(包括EUI)进行渲染
            const renderer = this.gameObject.getComponent(egret3d.Egret2DRenderer);
            const adapter = new egret3d.MatchWidthOrHeightAdapter();
            adapter.setResolution(egret3d.stage.screenViewport.w, egret3d.stage.screenViewport.h);
            renderer.screenAdapter = adapter;
            let assetAdapter = new AssetAdapter();
            egret.registerImplementation(“eui.IAssetAdapter”, assetAdapter);
            egret.registerImplementation(“eui.IThemeAdapter”, new ThemeAdapter());
            let theme = new eui.Theme(“resource/2d/default.thm.json”, renderer.stage);
            theme.addEventListener(eui.UIEvent.COMPLETE, onThemeLoadComplete, this);
            //2D的资源需要等这个回调才加载完毕
            function onThemeLoadComplete() {
                this.uiLayer = new eui.UILayer();
                this.uiLayer.touchEnabled = false;
                renderer.root.addChild(this.uiLayer);
                 //TODO
            }
        }
        onUpdate() {
        }
    }
}
//脚本组件。生命周期的顺序。
paper.Behaviour
和Unity类似 :
onAwake();
onStart();
onUpdate();
……等
class ThemeAdapter implements eui.IThemeAdapter {
        public getTheme(url: string, onSuccess: Function, onError: Function, thisObject: any): void {
            function onResGet(e: string): void {
                onSuccess.call(thisObject, e);
            }
            function onResError(e: RES.ResourceEvent): void {
                if (e.resItem.url == url) {
                    RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
                    onError.call(thisObject);
                }
            }
            if (typeof generateEUI !== ‘undefined’) {
                egret.callLater(() => {
                    onSuccess.call(thisObject, generateEUI);
                }, this);
            }
            else if (typeof generateEUI2 !== ‘undefined’) {
                RES.getResByUrl(“resource/gameEui.json”, (data, url) => {
                    window[“JSONParseClass”][“setData”](data);
                    onResGet(data);
                    egret.callLater(() => {
                        onSuccess.call(thisObject, generateEUI2);
                    }, this);
                }, this, RES.ResourceItem.TYPE_JSON);
            }
            else {
                RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, onResError, null);
                RES.getResByUrl(url, onResGet, this, RES.ResourceItem.TYPE_TEXT);
            }
}