BehaviorController.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. local BehaviorController = class('BehaviorController', framework.Mediator)
  2. BehaviorController.NAME = "BehaviorController"
  3. local BehaviorSelector = require("bt/BehaviorSelector")
  4. local facade = global.Facade
  5. function BehaviorController:ctor()
  6. BehaviorController.super.ctor(self, self.NAME)
  7. end
  8. function BehaviorController:destory()
  9. if BehaviorController.instance then
  10. facade:removeMediator( BehaviorController.NAME )
  11. BehaviorController.instance = nil
  12. end
  13. end
  14. function BehaviorController:Inst()
  15. if not BehaviorController.instance then
  16. BehaviorController.instance = BehaviorController.new()
  17. facade:registerMediator(BehaviorController.instance)
  18. end
  19. return BehaviorController.instance
  20. end
  21. function BehaviorController:InitOnEnterWorld()
  22. global.gamePlayerController:RegisterLuaInputHandler(handler(self, self.ProcessInput))
  23. self._selector = BehaviorSelector.new()
  24. end
  25. function BehaviorController:listNotificationInterests()
  26. local noticeTable = global.NoticeTable
  27. return
  28. {
  29. noticeTable.GameWorldInitComplete,
  30. }
  31. end
  32. function BehaviorController:handleNotification(notification)
  33. local noticeTable = global.NoticeTable
  34. local noticeID = notification:getName()
  35. local data = notification:getBody()
  36. if noticeTable.GameWorldInitComplete == noticeID then
  37. self:OnGameWorldInitComplete(data)
  38. end
  39. end
  40. function BehaviorController:ProcessInput(player, actCompleted)
  41. if self._selector then
  42. self._selector:process(player, actCompleted)
  43. end
  44. end
  45. function BehaviorController:OnGameWorldInitComplete(data)
  46. self._selector:Init()
  47. end
  48. return BehaviorController