GUIMediator.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import { GUIManager } from "./GUIManager";
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class GUIMediator{
  11. _view:fgui.GComponent;
  12. uiKey:number;
  13. data:any;
  14. /**
  15. * 内部接口
  16. * @param data
  17. */
  18. Show(data?:any):void{
  19. this.data=data;
  20. this.AddEvents();
  21. this.OnShow();
  22. }
  23. Hide():void{
  24. this.RemoveEvents();
  25. this.OnHide();
  26. }
  27. protected OnShow():void{
  28. }
  29. protected OnHide():void{
  30. }
  31. protected AddEvents():void{
  32. }
  33. protected RemoveEvents():void{
  34. }
  35. /**
  36. * 心跳
  37. * @param dt
  38. */
  39. Tick(dt:number):void{
  40. this.enterFrame();
  41. }
  42. /**
  43. * 关闭自己
  44. */
  45. HideSelf():void{
  46. GUIManager.single.Hide(this.uiKey);
  47. }
  48. /**
  49. * 销毁
  50. */
  51. OnDestory():void{
  52. }
  53. /**
  54. * 所在层次
  55. */
  56. get LayerIndex(){
  57. return 3;
  58. }
  59. /**
  60. * 下一帧需要回调的函数
  61. */
  62. private nextFrameCallHandler:Function[]=[];
  63. /**
  64. * 进入这一帧
  65. */
  66. enterFrame():void{
  67. this.nextFrameCallHandler.forEach(element => {
  68. element();
  69. });
  70. this.nextFrameCallHandler.length=0;
  71. }
  72. /**
  73. *
  74. * @param value 下一帧调用
  75. */
  76. CallNextFrame(value:Function):void{
  77. if(this.nextFrameCallHandler.indexOf(value)>=0){
  78. return;
  79. }
  80. this.nextFrameCallHandler.push(value);
  81. }
  82. }