BehaviorTree.cs 833 B

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