FireEventObserver.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import LogicUnitManager from './LogicUnitManager'
  2. import DataModelManager from 'DataModelManager'
  3. import GameProcessManager from '../net/GameProcessManager'
  4. import PlayerInfoModel from '../model/PlayerInfoModel';
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. },
  9. ctor: function () {
  10. // behavior
  11. this._behaviorEventIDMap = {};
  12. this.lum = LogicUnitManager;
  13. this._behaviorEvent_index = 0;
  14. // data model
  15. this._dataEventIDMap = {};
  16. this.dmm = DataModelManager;
  17. this._dataEvent_index = 0;
  18. },
  19. onBehaviorEvent(behaviorName,eventName,callbackFun)
  20. {
  21. let behavior = this.lum.getBehavior(behaviorName);
  22. if(behavior)
  23. {
  24. let eventId = behavior.on(eventName,callbackFun,this);
  25. this._behaviorEventIDMap[this._behaviorEvent_index++] = {'behavior':behavior,'id':eventId};
  26. }
  27. },
  28. onDataModelChange(modelName,attributename,callbackFun)
  29. {
  30. let model = this.dmm.getModel(modelName);
  31. if(model && typeof model.on !== 'undefined')
  32. {
  33. let eventId = model.on(attributename,callbackFun,this);
  34. this._dataEventIDMap[this._dataEvent_index++] = {'m':model,'id':eventId};
  35. }
  36. },
  37. onLoad () {
  38. },
  39. start () {
  40. },
  41. onDestroy()
  42. {
  43. // behavior destroy
  44. for(let val in this._behaviorEventIDMap)
  45. {
  46. let eid = this._behaviorEventIDMap[val]['id'];
  47. let behavior = this._behaviorEventIDMap[val]['behavior'];
  48. if(behavior)
  49. {
  50. behavior.off(eid);
  51. }
  52. }
  53. // data model destroy
  54. for(let val in this._dataEventIDMap)
  55. {
  56. let m = this._dataEventIDMap[val]['m'],eid = this._dataEventIDMap[val]['id'];
  57. if(m)
  58. {
  59. m.off(eid);
  60. }
  61. }
  62. },
  63. playShow(callbackFun)
  64. {
  65. this.node.opacity=0;
  66. this.node.runAction(cc.fadeIn(1.0));
  67. },
  68. playEnd(nextSence)
  69. {
  70. var callbackFun = null
  71. if (nextSence) {
  72. callbackFun = function(){
  73. cc.director.loadScene(nextSence)
  74. };
  75. }
  76. this.node.runAction(cc.sequence(cc.fadeOut(1.0),cc.callFunc(callbackFun)));
  77. }
  78. });