BehaviorTree.cs 906 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using Base;
  4. namespace Model
  5. {
  6. public class BehaviorTree
  7. {
  8. private readonly Node node;
  9. public BehaviorTreeConfig behaviorTreeConfig { get; set; }
  10. public Scene Scene { get; }
  11. public string Discription
  12. {
  13. get
  14. {
  15. return this.node.Description;
  16. }
  17. }
  18. public BehaviorTree(Scene scene, Node node)
  19. {
  20. this.Scene = scene;
  21. this.node = node;
  22. }
  23. public bool Run(BTEnv env)
  24. {
  25. try
  26. {
  27. bool ret = this.node.DoRun(this, env);
  28. List<long> pathList = env.Get<List<long>>(BTEnvKey.NodePath);
  29. Game.Scene.GetComponent<EventComponent>().Run(EventIdType.BehaviorTreeRunTreeEvent, this, pathList);
  30. return ret;
  31. }
  32. catch (Exception e)
  33. {
  34. string source = env.Get<string>(BTEnvKey.BTSource) ?? "";
  35. Log.Error($"树运行出错, 树名: {this.Discription} 来源: {source}" + e);
  36. return false;
  37. }
  38. }
  39. }
  40. }