Game.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { _decorator, Component, director, Node } from 'cc';
  2. import get_new_delay from '../../core/util_class/Delay';
  3. import get_new_fms from '../../core/util_class/FMS';
  4. import get_new_job from '../../core/util_class/TimeJobCenter';
  5. import get_new_random from '../../core/util_class/Random';
  6. import get_new_prefab_pool from '../../core/util_class/PrefabPool';
  7. import DirectorUtil from '../../core/util/DirectorUtil';
  8. /**
  9. * 游戏模块
  10. *
  11. const { ccclass, property } = _decorator;
  12. @ccclass('GameStar')
  13. export class GameStar extends Game<GameStar> {
  14. public cc:number=99;
  15. public tcc():void{
  16. console.log("goaodfjadsofjosadjfo"+this.cc);
  17. }
  18. onLoad(): void {
  19. super.onLoad();
  20. }
  21. update(deltaTime: number) {
  22. super.update(deltaTime);
  23. }
  24. async start() {
  25. console.log("111111111111111111111111111")
  26. await this.delay.start(3);
  27. console.log("3333333333333333333333333")
  28. GameStar.getInst().tcc();
  29. }
  30. }
  31. */
  32. export class Game<T extends Game<T>> extends Component {
  33. private static instance: Game<any>;
  34. public static getInst<T extends Game<T>>(this: new () => T): T {
  35. const _class = this as any;
  36. return _class.instance as T;
  37. }
  38. protected onLoad(): void {
  39. Game.instance = this;
  40. }
  41. /**游戏流程状态*/
  42. public FMS = get_new_fms();
  43. /**时间任务管理 暂停后不运行*/
  44. public job = get_new_job();
  45. /**延时管理*/
  46. public delay = get_new_delay();
  47. /**可设置种子的随机数*/
  48. public ranodm = get_new_random((new Date).getTime());
  49. /**预制体对象池*/
  50. public prefabPool = get_new_prefab_pool();
  51. private _paused: boolean = false;
  52. get is_paused(): boolean { return this._paused; }
  53. //
  54. public pause(): void {
  55. this._paused = true;
  56. DirectorUtil.pause();
  57. }
  58. //
  59. public resume(): void {
  60. this._paused = false;
  61. DirectorUtil.resume();
  62. }
  63. update(deltaTime: number) {
  64. this.delay.update(deltaTime);
  65. if (this._paused) return;
  66. this.job.Run(deltaTime);
  67. }
  68. }