Browse Source

增加事件:bbl引擎渲染各种状态改变时。

根据此事件,在暂停渲染时(即退出三维场景时),清空语音播报
dev
刘向辉 3 years ago
parent
commit
909c51e5d4
  1. 51
      src/app/babylon/controller/event-manager/events/event-engine-status-change.ts
  2. 14
      src/app/babylon/game.ts
  3. 23
      src/app/babylon/tool/speaking-tool.ts

51
src/app/babylon/controller/event-manager/events/event-engine-status-change.ts

@ -0,0 +1,51 @@
import { Event_Base } from "../event-base";
import { EventManager } from "../event-manager";
/**
*
*/
export class Event_EngineStatusChange extends Event_Base {
/**
*
*/
changeType: EngineStatusChangeType;
/**
*
* @param modeleInfo
* @param modelChangeType
*/
static dispatch(changeType: EngineStatusChangeType) {
let eventData = new Event_EngineStatusChange();
eventData.changeType = changeType;
EventManager.dispatch<Event_EngineStatusChange>(Event_EngineStatusChange, eventData);
}
getTypeKey() {
return "EngineStatusChangeType";
}
}
/**
*
*/
export enum EngineStatusChangeType {
/**
*
*/
init,
/**
*
*/
dispose,
/**
*
*/
pause,
/**
*
*/
start,
}

14
src/app/babylon/game.ts

@ -1,4 +1,5 @@
import { AbstractMesh, Database, Engine, FileTools, Mesh, RenderingManager, Scene } from "@babylonjs/core";
import { EngineStatusChangeType, Event_EngineStatusChange } from "./controller/event-manager/events/event-engine-status-change";
import { SceneManager } from "./controller/scene-manager";
import { LoginSatus } from "./controller/status/login-status";
@ -23,10 +24,6 @@ export class Game {
// FileTools.DefaultRetryStrategy = RetryStrategy.ExponentialBackoff(2, 1000);
if (Game.instance != null) {
// canvas.setAttribute("touch-action", "none");
// canvas.style.touchAction = "none";
// canvas.tabIndex = 1;
this.startRender();
this.scene.detachControl();
let view = this.engine.registerView(canvas, SceneManager.Instance.defaultCamera);
this.canvas = canvas;
@ -35,11 +32,12 @@ export class Game {
this.canvas.addEventListener('contextmenu', function (e) {
e.preventDefault();
})
this.startRender();
SceneManager.Instance.defaultCamera.attachControl(canvas, true);
}
else {
this.startRender();
Game.instance = this;
this.canvas = canvas;
this.engine = new Engine(canvas, null, { stencil: true });
@ -50,6 +48,8 @@ export class Game {
this.createScene();
UIManager.Instance.init();
let scene = this.scene;
Event_EngineStatusChange.dispatch(EngineStatusChangeType.init);
this.startRender();
//最后,将场景渲染出来 (重要,不可缺少)
this.engine.runRenderLoop(function () {
if (Game.instance != null && Game.instance.isRender) {
@ -86,7 +86,7 @@ export class Game {
}
dispose() {
SpeakingTool.Instance.clear();
Event_EngineStatusChange.dispatch(EngineStatusChangeType.dispose);
SceneManager.Instance.dispose();
StatusManager.dispose();
this.scene.dispose()
@ -101,6 +101,7 @@ export class Game {
pauseRender() {
this.engine.unRegisterView(this.canvas);
this.isRender = false;
Event_EngineStatusChange.dispatch(EngineStatusChangeType.pause);
}
/**
@ -108,6 +109,7 @@ export class Game {
*/
startRender() {
this.isRender = true;
Event_EngineStatusChange.dispatch(EngineStatusChangeType.start);
}

23
src/app/babylon/tool/speaking-tool.ts

@ -1,4 +1,5 @@
import { EventManager } from "../controller/event-manager/event-manager";
import { EngineStatusChangeType, Event_EngineStatusChange } from "../controller/event-manager/events/event-engine-status-change";
import { Event_LoadingChange } from "../controller/event-manager/events/event-loading-change";
/**
@ -11,10 +12,26 @@ export class SpeakingTool {
static get Instance() {
if (SpeakingTool.instance == null) {
SpeakingTool.instance = new SpeakingTool();
EventManager.addListener<Event_LoadingChange>(Event_LoadingChange, (eventInfo) => {
SpeakingTool.instance.onChangeLoading(eventInfo);
});
EventManager.addListener<Event_EngineStatusChange>(Event_EngineStatusChange, (eventData) => {
switch (eventData.changeType) {
//退出三维时,清空语音播报
case EngineStatusChangeType.pause:
SpeakingTool.instance.clear();
break;
case EngineStatusChangeType.dispose:
SpeakingTool.instance.clear();
break;
}
})
}
EventManager.addListener<Event_LoadingChange>(Event_LoadingChange, (eventInfo) => {
SpeakingTool.instance.onChangeLoading(eventInfo);
});
return SpeakingTool.instance;
}

Loading…
Cancel
Save