2 changed files with 74 additions and 0 deletions
@ -0,0 +1,34 @@ |
|||
import { Container, Ticker } from "pixi.js"; |
|||
import { SceneType } from "@/enums/SceneType"; |
|||
import type { IBaseScene, SceneLifeCycle } from "./types"; |
|||
|
|||
export abstract class BaseScene implements IBaseScene { |
|||
abstract stage: Container; |
|||
readonly name: string; |
|||
readonly type: SceneType; |
|||
|
|||
_assetsLoaded: boolean = false; |
|||
_layoutDone: boolean = false; |
|||
|
|||
constructor(name: string, type: SceneType = SceneType.Normal) { |
|||
this.name = name; |
|||
this.type = type; |
|||
} |
|||
|
|||
// 用于注入场景切换方法
|
|||
changeScene(name: string, options?: { isHolderLast?: boolean }): void { |
|||
// 由 SceneManager 注入实现
|
|||
throw new Error("changeScene not injected by SceneManager"); |
|||
} |
|||
|
|||
// 生命周期方法 - 默认空实现
|
|||
async loadBundle(): Promise<void> {} |
|||
async unLoadBundle(): Promise<void> {} |
|||
layout(): void | Promise<void> {} |
|||
onLoad(): void | Promise<void> {} |
|||
onUnLoad(): void | Promise<void> {} |
|||
update(dt: number, ticker: Ticker): void {} |
|||
lateUpdate(dt: number, ticker: Ticker): void {} |
|||
} |
|||
|
|||
export default BaseScene; |
|||
@ -0,0 +1,40 @@ |
|||
import { Container, Ticker } from "pixi.js"; |
|||
import { SceneType } from "@/enums/SceneType"; |
|||
|
|||
export interface SceneConfig { |
|||
name: string; |
|||
type: SceneType; |
|||
stage: Container; |
|||
} |
|||
|
|||
export interface SceneLifeCycle { |
|||
/** 加载资源包 */ |
|||
loadBundle?(): Promise<void>; |
|||
/** 卸载资源包 */ |
|||
unLoadBundle?(): Promise<void>; |
|||
/** 创建布局 */ |
|||
layout?(): void | Promise<void>; |
|||
/** 场景加载完成 */ |
|||
onLoad?(): void | Promise<void>; |
|||
/** 场景即将卸载 */ |
|||
onUnLoad?(): void | Promise<void>; |
|||
/** 每帧更新 */ |
|||
update?(dt: number, ticker: Ticker): void; |
|||
/** 更新后处理 */ |
|||
lateUpdate?(dt: number, ticker: Ticker): void; |
|||
} |
|||
|
|||
export interface IBaseScene extends SceneLifeCycle { |
|||
/** 场景容器 */ |
|||
stage: Container; |
|||
/** 场景名称 */ |
|||
readonly name: string; |
|||
/** 场景类型 */ |
|||
readonly type: SceneType; |
|||
/** 是否已加载资源 */ |
|||
_assetsLoaded: boolean; |
|||
/** 是否已布局 */ |
|||
_layoutDone: boolean; |
|||
/** 改变场景 */ |
|||
changeScene(name: string, options?: { isHolderLast?: boolean }): void; |
|||
} |
|||
Loading…
Reference in new issue