Node.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Collections.Generic;
  2. namespace ETModel
  3. {
  4. public abstract class Node
  5. {
  6. private long id;
  7. private string description;
  8. protected readonly List<Node> children = new List<Node>();
  9. protected Node(NodeProto nodeProto)
  10. {
  11. this.id = nodeProto.Id;
  12. this.description = nodeProto.Desc;
  13. this.NodeProto = nodeProto;
  14. }
  15. public Node[] GetChildren
  16. {
  17. get
  18. {
  19. return children.ToArray();
  20. }
  21. }
  22. public NodeProto NodeProto { get; }
  23. public string Description
  24. {
  25. get
  26. {
  27. return this.description;
  28. }
  29. set
  30. {
  31. this.description = value;
  32. }
  33. }
  34. /// <summary>
  35. /// 策划配置的id
  36. /// </summary>
  37. public long Id
  38. {
  39. get
  40. {
  41. return this.id;
  42. }
  43. set
  44. {
  45. this.id = value;
  46. }
  47. }
  48. /// <summary>
  49. /// 节点的类型例如: NodeType.Not
  50. /// </summary>
  51. public string Type
  52. {
  53. get
  54. {
  55. return this.NodeProto.Name;
  56. }
  57. }
  58. public void AddChild(Node child)
  59. {
  60. this.children.Add(child);
  61. }
  62. public virtual void EndInit(Scene scene)
  63. {
  64. }
  65. public bool DoRun(BehaviorTree behaviorTree, BTEnv env)
  66. {
  67. env.Get<List<long>>(BTEnvKey.NodePath).Add(this.NodeProto.Id);
  68. return this.Run(behaviorTree, env);
  69. }
  70. protected abstract bool Run(BehaviorTree behaviorTree, BTEnv env);
  71. }
  72. }