RootScene.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { _EJsonRes } from "./Engine/Data/CommonDataType";
  2. import Engine from "./Engine/Engine";
  3. import EventManager from "./Engine/Event/EventManager";
  4. import JsonResources from "./Engine/Resources/JsonResources";
  5. import GameBehaviorTree from "./Game/BehaviorTree/GameBehaviorTree";
  6. import DataManager from "./Game/Data/DataManager";
  7. import { ConstObject, _EGameBehavior, _EGameJsonRes } from "./Game/Data/GameDataType";
  8. import GameEventName from "./Game/Event/GameEventName";
  9. import UnitManager from "./Game/Unit/UnitManager";
  10. import InitLoadView from "./Game/View/InitLoadView/InitLoadView";
  11. import SDKManager from "./Game/SDK/SDKManager";
  12. import Tool from "./Engine/Tool/Tool";
  13. const {ccclass, property} = cc._decorator;
  14. @ccclass
  15. export default class Helloworld extends cc.Component {
  16. start () {
  17. Tool.isLog = false;
  18. cc.assetManager.loadBundle("res/cocos", (err: Error, cocos: cc.AssetManager.Bundle) => {
  19. cc.assetManager.loadBundle("res/fgui", (err: Error, fgui: cc.AssetManager.Bundle) => {
  20. // 首次加载必要的配置表
  21. let res: Array<string> = [
  22. _EJsonRes.GameConfig,
  23. _EJsonRes.ViewConfig,
  24. _EJsonRes.GameBehaviorTree,
  25. _EGameJsonRes.UserDataConfig,
  26. ];
  27. JsonResources.loadJsonResources(ConstObject.ResPath, res, 0, 0, () => {
  28. new Engine((engine: Engine) => {
  29. // 获取用户数据
  30. EventManager.onEvent(GameEventName.UserData.UserData_ReadUserData, this, (gameBehavior: _EGameBehavior) => {
  31. // 创建游戏行为树
  32. new GameBehaviorTree(this.node, JsonResources.getResources(_EJsonRes.GameBehaviorTree));
  33. // 进入初始加载页
  34. let map: Object = (fgui as any)._config.paths._map;
  35. let initLoadView: Array<string> = [];
  36. for (let index in map) {
  37. if (index.includes(InitLoadView.resPath) == true) {
  38. initLoadView.push(index);
  39. }
  40. }
  41. fgui.load(initLoadView, (error: Error, assets: cc.Asset[]) => {
  42. EventManager.sendEventByTargetID(GameEventName.Behavior.Behavior_EnterBehavior, ConstObject.GameBehaviorTreeID, gameBehavior);
  43. });
  44. });
  45. // 创建全局管理器
  46. engine.managers.push(new UnitManager());
  47. engine.managers.push(new SDKManager());
  48. engine.managers.push(new DataManager());
  49. });
  50. });
  51. });
  52. });
  53. }
  54. }