|
|
|
@ -11,6 +11,8 @@ export class Game {
|
|
|
|
|
public engine: Engine; |
|
|
|
|
public scene: Scene; |
|
|
|
|
|
|
|
|
|
private isRender: boolean = true;//是否更新渲染
|
|
|
|
|
|
|
|
|
|
static instance: Game; |
|
|
|
|
|
|
|
|
|
//初始化引擎和画布
|
|
|
|
@ -18,7 +20,24 @@ export class Game {
|
|
|
|
|
|
|
|
|
|
// FileTools.DefaultRetryStrategy = MyRetryStrategy.ExponentialBackoff(2, 1000);
|
|
|
|
|
// 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; |
|
|
|
|
this.engine.inputElement = canvas; |
|
|
|
|
this.scene.attachControl(); |
|
|
|
|
this.canvas.addEventListener('contextmenu', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
}) |
|
|
|
|
SceneManager.Instance.defaultCamera.attachControl(canvas, true); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
this.startRender(); |
|
|
|
|
Game.instance = this; |
|
|
|
|
this.canvas = canvas; |
|
|
|
|
this.engine = new Engine(canvas, null, { stencil: true }); |
|
|
|
@ -26,27 +45,38 @@ export class Game {
|
|
|
|
|
this.scene = new Scene(this.engine); |
|
|
|
|
this.scene.useRightHandedSystem = true;//使用右手坐标系
|
|
|
|
|
RenderingManager.MIN_RENDERINGGROUPS = -1;//最小渲染序列
|
|
|
|
|
// Engine.DefaultLoadingScreenFactory() //尝试更改canvas
|
|
|
|
|
this.createScene(); |
|
|
|
|
let scene = this.scene; |
|
|
|
|
// canvas.translate = true; //用于设置背景透明
|
|
|
|
|
// scene.autoClear = true;
|
|
|
|
|
UIManager.Instance.init(); |
|
|
|
|
|
|
|
|
|
StatusManager.enterStatus<LoginSatus>(LoginSatus); |
|
|
|
|
|
|
|
|
|
let scene = this.scene; |
|
|
|
|
//最后,将场景渲染出来 (重要,不可缺少)
|
|
|
|
|
this.engine.runRenderLoop(function () { |
|
|
|
|
if (Game.instance != null && Game.instance.isRender) { |
|
|
|
|
scene.render(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 监听浏览器改变大小的事件,通过调用engine.resize()来自适应窗口大小
|
|
|
|
|
window.addEventListener("resize", function () { |
|
|
|
|
if (Game.instance != null) { |
|
|
|
|
if (Game.instance != null && Game.instance.isRender) { |
|
|
|
|
Game.instance.engine.resize(); |
|
|
|
|
UIManager.Instance.uiRoot.renderScale = 0.99; |
|
|
|
|
setTimeout(() => { |
|
|
|
|
UIManager.Instance.uiRoot.renderScale = 1; |
|
|
|
|
}, 10); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
StatusManager.enterStatus<LoginSatus>(LoginSatus); |
|
|
|
|
|
|
|
|
|
// canvas.translate = true; //用于设置背景透明
|
|
|
|
|
// scene.autoClear = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -66,8 +96,25 @@ export class Game {
|
|
|
|
|
this.scene = null; |
|
|
|
|
this.engine.dispose(); |
|
|
|
|
this.engine = null; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 暂停渲染 |
|
|
|
|
*/ |
|
|
|
|
pauseRender() { |
|
|
|
|
this.engine.unRegisterView(this.canvas); |
|
|
|
|
this.isRender = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 开始或继续渲染 |
|
|
|
|
*/ |
|
|
|
|
startRender() { |
|
|
|
|
this.isRender = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// /**
|
|
|
|
|