BehaviorTree.cs 845 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 Scene Scene { get; }
  10. public string Discription
  11. {
  12. get
  13. {
  14. return this.node.Description;
  15. }
  16. }
  17. public BehaviorTree(Scene scene, Node node)
  18. {
  19. this.Scene = scene;
  20. this.node = node;
  21. }
  22. public bool Run(BTEnv env)
  23. {
  24. try
  25. {
  26. bool ret = this.node.DoRun(this, env);
  27. List<long> pathList = env.Get<List<long>>(BTEnvKey.NodePath);
  28. Game.Scene.GetComponent<EventComponent>().Run(EventIdType.BehaviorTreeRunTreeEvent, this, pathList);
  29. return ret;
  30. }
  31. catch (Exception e)
  32. {
  33. string source = env.Get<string>(BTEnvKey.BTSource) ?? "";
  34. Log.Error($"树运行出错, 树名: {this.Discription} 来源: {source}" + e);
  35. return false;
  36. }
  37. }
  38. }
  39. }