RootScene.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.director.getScene().getChildByName("Canvas").zIndex = 100;
  19. cc.assetManager.loadBundle("res/cocos", (err: Error, cocos: cc.AssetManager.Bundle) => {
  20. cc.assetManager.loadBundle("res/fgui", (err: Error, fgui: cc.AssetManager.Bundle) => {
  21. // 首次加载必要的配置表
  22. let res: Array<string> = [
  23. _EJsonRes.GameConfig,
  24. _EJsonRes.ViewConfig,
  25. _EJsonRes.GameBehaviorTree,
  26. _EGameJsonRes.UserDataConfig,
  27. ];
  28. JsonResources.loadJsonResources(ConstObject.ResPath, res, 0, 0, () => {
  29. new Engine((engine: Engine) => {
  30. // 获取用户数据
  31. EventManager.onEvent(GameEventName.UserData.UserData_ReadUserData, this, (gameBehavior: _EGameBehavior) => {
  32. // 创建游戏行为树
  33. new GameBehaviorTree(this.node, JsonResources.getResources(_EJsonRes.GameBehaviorTree));
  34. // 进入初始加载页
  35. let map: Object = (fgui as any)._config.paths._map;
  36. let initLoadView: Array<string> = [];
  37. for (let index in map) {
  38. if (index.includes(InitLoadView.resPath) == true) {
  39. initLoadView.push(index);
  40. }
  41. }
  42. fgui.load(initLoadView, (error: Error, assets: cc.Asset[]) => {
  43. EventManager.sendEventByTargetID(GameEventName.Behavior.Behavior_EnterBehavior, ConstObject.GameBehaviorTreeID, gameBehavior);
  44. });
  45. });
  46. // 创建全局管理器
  47. engine.managers.push(new UnitManager());
  48. engine.managers.push(new SDKManager());
  49. engine.managers.push(new DataManager());
  50. });
  51. });
  52. });
  53. });
  54. }
  55. }