{ "code": "var Vector3 = Laya.Vector3;\r\nimport { EventManager, EventType } from \"./EventManager\";\r\nimport { GameState, TouchState } from \"./DataMaker\";\r\nexport class InputManager {\r\n constructor() {\r\n this.curtouthstate = TouchState.none;\r\n this.touchPos = new Vector3();\r\n this.curMousePos = new Vector3(0, 0, 0);\r\n this.sliderawakesize = 5;\r\n this.curdir = new Vector3();\r\n this.curtouchpos = new Vector3();\r\n InputManager.instance = this;\r\n this.Init();\r\n }\r\n static get Instance() {\r\n return InputManager.instance;\r\n }\r\n Init() {\r\n Laya.stage.on(Laya.Event.MOUSE_DOWN, this, this.TouchEnter);\r\n Laya.stage.on(Laya.Event.MOUSE_UP, this, this.OnTouchOut);\r\n Laya.stage.on(Laya.Event.MOUSE_OUT, this, this.OnTouchOut);\r\n EventManager.GameOn(GameState.Ready, this, this.OnGameReady);\r\n EventManager.GameOn(GameState.Playing, this, this.OnGamePlaying);\r\n EventManager.GameOn(GameState.Resurrection, this, this.OnGameResurrection);\r\n EventManager.GameOn(GameState.Lose, this, this.OnGameLose);\r\n EventManager.GameOn(GameState.Win, this, this.OnGameWin);\r\n }\r\n OnGameReady() {\r\n Laya.timer.clear(this, this.OnTouchMove);\r\n this.curtouthstate = TouchState.down;\r\n InputManager.caninput = true;\r\n }\r\n OnGamePlaying() {\r\n InputManager.caninput = true;\r\n }\r\n OnGameResurrection() {\r\n Laya.timer.clear(this, this.OnTouchMove);\r\n this.curtouthstate = TouchState.down;\r\n InputManager.caninput = false;\r\n }\r\n OnGameLose() {\r\n Laya.timer.clear(this, this.OnTouchMove);\r\n this.curtouthstate = TouchState.down;\r\n InputManager.caninput = false;\r\n }\r\n OnGameWin() {\r\n Laya.timer.clear(this, this.OnTouchMove);\r\n this.curtouthstate = TouchState.down;\r\n InputManager.caninput = false;\r\n }\r\n TouchEnter(e) {\r\n this.curtouthstate = TouchState.down;\r\n EventManager.Trigger(EventType.InputState, [this.curtouthstate]);\r\n if (!InputManager.caninput)\r\n return;\r\n this.curtouchpos = new Laya.Vector3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY, 0);\r\n Laya.timer.clear(this, this.OnTouchMove);\r\n EventManager.InputTrigger(TouchState.down, [this.curMousePos]);\r\n Laya.timer.frameLoop(1, this, this.OnTouchMove);\r\n }\r\n OnTouchOut() {\r\n this.curtouthstate = TouchState.up;\r\n EventManager.Trigger(EventType.InputState, [this.curtouthstate]);\r\n if (!InputManager.caninput)\r\n return;\r\n Laya.timer.clear(this, this.OnTouchMove);\r\n EventManager.InputTrigger(TouchState.up);\r\n }\r\n OnTouchMove() {\r\n this.curtouthstate = TouchState.slider;\r\n EventManager.Trigger(EventType.InputState, [this.curtouthstate]);\r\n if (!InputManager.caninput)\r\n return;\r\n this.curMousePos = new Laya.Vector3(Laya.MouseManager.instance.mouseX, Laya.MouseManager.instance.mouseY, 0);\r\n var distance = Vector3.distance(this.curtouchpos, this.curMousePos);\r\n if (distance > this.sliderawakesize) {\r\n Vector3.subtract(this.curtouchpos, this.curMousePos, this.curdir);\r\n Vector3.normalize(this.curdir, this.curdir);\r\n EventManager.InputTrigger(TouchState.slider, [new Vector3(this.curdir.x, 0, this.curdir.y)]);\r\n }\r\n }\r\n}\r\nInputManager.caninput = false;\r\n", "references": [ "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/EventManager.ts", "D:/Work/samurai2-laya/laya/samuraiflash-tt/src/Main/DataMaker.ts" ] }