import { GameObjectBase, GameObjectBaseType, GameObjectData, spmExpo, } from '@gedit/render-engine'; import { PixiGameScene } from '../../common'; export interface SceneSchema { // lightsEnable: boolean; // ambientColor: string; backgroundColor?: string; width?: number; // 场景宽 height?: number; // 场景高 autoSize?: boolean; disableScroll?: boolean; scrollXBool: boolean; scrollYBool: boolean; closeScrollResistance: boolean; logC?: string; // c位埋点曝光; } export interface SceneGameObjectData extends GameObjectData { [GameObjectBaseType.SCENE]: SceneSchema; } export class SceneGameObject extends GameObjectBase< SceneGameObjectData, PixiGameScene > { static type = GameObjectBaseType.SCENE; protected timeout: any; // resize 延时用 protected winResize: any; create(): void { this.scene.root = this; super.create.apply(this, arguments); this.winResize = this.onResize.bind(this); if (!this.scene.config.isIDE) { window.addEventListener('resize', this.winResize); } } // render 状态下,场景创建后调用曝光; onSceneCreated(): void { const logText = this.data[GameObjectBaseType.SCENE].logC; spmExpo(logText); } protected onResize(): void { console.log('resize'); clearTimeout(this.timeout); this.timeout = setTimeout(() => { this.scene.updateConfig(this.data.scene); }, 16.6667); } dispose(): void { super.dispose(); clearTimeout(this.timeout); this.timeout = undefined; // const config = this.data.scene; if (!this.scene.config.isIDE) { console.log('scene dispose'); window.removeEventListener('resize', this.winResize); } } protected getSize(data: SceneSchema): { width: number; height: number } { if (data.autoSize) { return { width: this.scene.config.width, height: this.scene.config.height, }; } return { width: data.width || this.scene.config.width, height: data.height || this.scene.config.height, }; } /** * 刷新子节点的depth */ refreshChildrenDepth(): void { // this.rendererObject?.sort('depth'); } update(data: SceneGameObjectData): void { const sceneData = data[GameObjectBaseType.SCENE] as SceneSchema; this.scene.updateConfig(sceneData); super.update(data); } getRendererObject(): PIXI.Container | undefined { return this.scene.container; } }