BTTest.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ---
  2. --- Generated by EmmyLua(https://github.com/EmmyLua)
  3. --- Created by PZM.
  4. --- DateTime: 2025/1/20 9:34
  5. ---@class BTTest
  6. BTTest = {}
  7. local this = BTTest
  8. function this.Init()
  9. ---@type BehaviorTree
  10. this.btEventTest = BTEventTest(this).BTree
  11. this.btEventTest:Start()
  12. end
  13. ---@class BTEventTest: BehaviorEvent
  14. BTEventTest = class(SL.BtTree:BehaviorEvent())
  15. local this= BTEventTest
  16. function this:ctor(mgr)
  17. SL.BtTree:BehaviorEvent().ctor(self, mgr)
  18. end
  19. function this:Init()
  20. local root = nil
  21. root = IfNode(this.IsAutoDragVaild,
  22. BTNodeTest()
  23. )
  24. self.BTree = SL.BtTree:BehaviorTree()(root, self)
  25. end
  26. function this:Start()
  27. if not self.BTree:IsUpdateIn() then
  28. self.BTree:Reset()
  29. self.BTree:Start()
  30. end
  31. end
  32. function this:IsUpdateIn()
  33. return self.BTree:IsUpdateIn()
  34. end
  35. function this:Stop()
  36. self.BTree:Cancel()
  37. end
  38. function this.IsAutoDragVaild()
  39. return true
  40. end
  41. ---@class BTNodeTest:BehaviorNode
  42. BTNodeTest = class(BehaviorNode)
  43. local this = BTNodeTest
  44. function this:ctor()
  45. BehaviorNode.ctor(self)
  46. --self.kind = BehaviorNodeEnum.HPProtectNode
  47. --self.nodeName = BehaviorNodeStringEnum[self.kind]
  48. self.kind = table.count(BehaviorNodeEnum)+1 --自定义枚举值
  49. self.nodeName = "自定义节点名称"
  50. end
  51. function this:Visit()
  52. local bUseOk = true
  53. if bUseOk then
  54. SL:LogError('BTNodeTest Visit')
  55. self.status = BehaviorStatusEnum.SUCCESS
  56. else
  57. self.status = BehaviorStatusEnum.FAILED
  58. end
  59. end
  60. BTTest.Init()