bundle.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. (function () {
  2. 'use strict';
  3. class GameConfig {
  4. constructor() { }
  5. static init() {
  6. var reg = Laya.ClassUtils.regClass;
  7. }
  8. }
  9. GameConfig.width = 640;
  10. GameConfig.height = 1136;
  11. GameConfig.scaleMode = "fixedwidth";
  12. GameConfig.screenMode = "none";
  13. GameConfig.alignV = "top";
  14. GameConfig.alignH = "left";
  15. GameConfig.startScene = "";
  16. GameConfig.sceneRoot = "";
  17. GameConfig.debug = false;
  18. GameConfig.stat = false;
  19. GameConfig.physicsDebug = false;
  20. GameConfig.exportSceneToJson = true;
  21. GameConfig.init();
  22. class ResDic {
  23. constructor() {
  24. this._container = {};
  25. this._length = 0;
  26. }
  27. get container() {
  28. return this._container;
  29. }
  30. get size() {
  31. return this._length;
  32. }
  33. set(key, value) {
  34. if (!this._container.hasOwnProperty(key)) {
  35. this._length++;
  36. }
  37. this._container[key] = value;
  38. }
  39. has(key) {
  40. return this._container.hasOwnProperty(key) ? true : false;
  41. }
  42. get(key) {
  43. if (this._container.hasOwnProperty(key)) {
  44. return this._container[key];
  45. }
  46. else {
  47. return undefined;
  48. }
  49. }
  50. delete(key) {
  51. if (this._container.hasOwnProperty(key)) {
  52. delete this._container[key];
  53. this._length--;
  54. }
  55. }
  56. clear() {
  57. this._container = {};
  58. this._length = 0;
  59. }
  60. }
  61. class AssetManager {
  62. constructor() {
  63. this.Zombie = new ResDic();
  64. this.Police = new ResDic();
  65. this.People = new ResDic();
  66. AssetManager.ins = this;
  67. }
  68. static get Instance() {
  69. if (AssetManager.ins) {
  70. return AssetManager.ins;
  71. }
  72. else {
  73. return new AssetManager();
  74. }
  75. }
  76. Init() {
  77. Laya.stage.addChild(this.mainscene);
  78. this.maincamera = this.mainscene.getChildByName("MainCamera");
  79. }
  80. }
  81. class ResourcesPath {
  82. constructor() {
  83. ResourcesPath.ins = this;
  84. }
  85. static get Instance() {
  86. if (ResourcesPath.ins) {
  87. return ResourcesPath.ins;
  88. }
  89. else {
  90. return new ResourcesPath();
  91. }
  92. }
  93. }
  94. ResourcesPath.MainScene = "Game/res/MainScene/LayaScene_mainscene/Conventional/mainscene.ls";
  95. ResourcesPath.People = [
  96. "Game/res/Role/LayaScene_mainscene/Conventional/role1.lh",
  97. "Game/res/Role/LayaScene_mainscene/Conventional/role2.lh",
  98. "Game/res/Role/LayaScene_mainscene/Conventional/role3.lh"
  99. ];
  100. ResourcesPath.Police = "Game/res/Role/LayaScene_mainscene/Conventional/police.lh";
  101. ResourcesPath.Zombie = "Game/res/Role/LayaScene_mainscene/Conventional/Zombie.lh";
  102. var DispatcherState;
  103. (function (DispatcherState) {
  104. DispatcherState[DispatcherState["LoadComplete"] = 0] = "LoadComplete";
  105. DispatcherState[DispatcherState["SceneInit"] = 1] = "SceneInit";
  106. DispatcherState[DispatcherState["StageInit"] = 2] = "StageInit";
  107. DispatcherState[DispatcherState["StageCreateComplete"] = 3] = "StageCreateComplete";
  108. DispatcherState[DispatcherState["GoldGet"] = 4] = "GoldGet";
  109. DispatcherState[DispatcherState["PlayerRunning"] = 5] = "PlayerRunning";
  110. DispatcherState[DispatcherState["PlayerStand"] = 6] = "PlayerStand";
  111. DispatcherState[DispatcherState["ShowModel"] = 7] = "ShowModel";
  112. DispatcherState[DispatcherState["RefreshCityName"] = 8] = "RefreshCityName";
  113. })(DispatcherState || (DispatcherState = {}));
  114. class DispatcherControl {
  115. static DispatcherOn(_mode, caller, fun, args = []) {
  116. DispatcherControl.instance.on(DispatcherState[_mode], caller, fun, args);
  117. }
  118. static DispatcherOff(_mode, caller, fun, args = []) {
  119. DispatcherControl.instance.off(DispatcherState[_mode], caller, fun);
  120. }
  121. static DispatcherTrigger(_mode, args = []) {
  122. DispatcherControl.instance.event(DispatcherState[_mode], args);
  123. }
  124. }
  125. DispatcherControl.instance = new Laya.EventDispatcher();
  126. class CameraControl {
  127. constructor() {
  128. CameraControl.ins = this;
  129. DispatcherControl.DispatcherOn(DispatcherState.LoadComplete, this, this.Init);
  130. }
  131. static get Instance() {
  132. if (CameraControl.ins) {
  133. return CameraControl.ins;
  134. }
  135. else {
  136. return new CameraControl();
  137. }
  138. }
  139. Init() {
  140. this.maincamera = LoadView.Instance.maincamera;
  141. this.maincamera.transform.position = new Laya.Vector3(19.5, 100, 16.7);
  142. }
  143. }
  144. class LoadView {
  145. constructor() {
  146. LoadView.ins = this;
  147. new CameraControl();
  148. this.Init();
  149. }
  150. static get Instance() {
  151. if (LoadView.ins) {
  152. return LoadView.ins;
  153. }
  154. else {
  155. return new LoadView();
  156. }
  157. }
  158. Init() {
  159. this.LoadScene();
  160. }
  161. LoadScene() {
  162. Laya.Scene3D.load(ResourcesPath.MainScene, Laya.Handler.create(this, (scene) => {
  163. this.mainscene = scene;
  164. this.maincamera = this.mainscene.getChildByName("Main Camera");
  165. console.log(this.maincamera);
  166. Laya.stage.addChild(this.mainscene);
  167. console.log("场景加载完毕--");
  168. this.LoadZombie();
  169. }));
  170. }
  171. LoadZombie() {
  172. Laya.loader.create(ResourcesPath.Zombie, Laya.Handler.create(this, (zombie) => {
  173. AssetManager.Instance.Zombie.set(1, zombie);
  174. }));
  175. console.log("僵尸模型加载完毕--");
  176. this.LoadPolice();
  177. }
  178. LoadPolice() {
  179. Laya.loader.create(ResourcesPath.Police, Laya.Handler.create(this, (police) => {
  180. AssetManager.Instance.Police.set(1, police);
  181. console.log("警察模型加载完毕--");
  182. this.LoadPeople();
  183. }));
  184. }
  185. LoadPeople() {
  186. var path = [];
  187. for (let i = 0; i < ResourcesPath.People.length; i++) {
  188. path.push(ResourcesPath.People[i]);
  189. }
  190. Laya.loader.create(path, Laya.Handler.create(this, () => {
  191. for (var i = 0; i < ResourcesPath.People.length; i++) {
  192. var people = Laya.loader.getRes(ResourcesPath.People[i]);
  193. AssetManager.Instance.People.set(i + 1, people);
  194. Laya.loader.clearRes(ResourcesPath.People[i]);
  195. }
  196. console.log("平民模型加载完毕--");
  197. DispatcherControl.DispatcherTrigger(DispatcherState.LoadComplete);
  198. }));
  199. }
  200. }
  201. class CheckMain {
  202. }
  203. CheckMain.Create = false;
  204. class Main {
  205. constructor() {
  206. if (CheckMain.Create)
  207. return;
  208. CheckMain.Create = true;
  209. if (window["Laya3D"])
  210. Laya3D.init(GameConfig.width, GameConfig.height);
  211. else
  212. Laya.init(GameConfig.width, GameConfig.height, Laya["WebGL"]);
  213. Laya["Physics"] && Laya["Physics"].enable();
  214. Laya["DebugPanel"] && Laya["DebugPanel"].enable();
  215. Laya.stage.scaleMode = GameConfig.scaleMode;
  216. Laya.stage.screenMode = GameConfig.screenMode;
  217. Laya.stage.alignV = GameConfig.alignV;
  218. Laya.stage.alignH = GameConfig.alignH;
  219. Laya.URL.exportSceneToJson = GameConfig.exportSceneToJson;
  220. if (GameConfig.debug || Laya.Utils.getQueryString("debug") == "true")
  221. Laya.enableDebugPanel();
  222. if (GameConfig.physicsDebug && Laya["PhysicsDebugDraw"])
  223. Laya["PhysicsDebugDraw"].enable();
  224. if (GameConfig.stat)
  225. Laya.Stat.show();
  226. Laya.alertGlobalError = true;
  227. Laya.ResourceVersion.enable("version.json", Laya.Handler.create(this, this.onVersionLoaded), Laya.ResourceVersion.FILENAME_VERSION);
  228. }
  229. onVersionLoaded() {
  230. Laya.AtlasInfoManager.enable("fileconfig.json", Laya.Handler.create(this, this.onConfigLoaded));
  231. }
  232. onConfigLoaded() {
  233. new LoadView();
  234. }
  235. }
  236. new Main();
  237. }());
  238. //# sourceMappingURL=bundle.js.map