| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- using System.Collections.Generic;
- namespace Model
- {
- public class BehaviorTree
- {
- private readonly Node node;
- public Scene Scene { get; }
- public string Discription
- {
- get
- {
- return this.node.Description;
- }
- }
- public BehaviorTree(Scene scene, Node node)
- {
- this.Scene = scene;
- this.node = node;
- }
- public bool Run(BTEnv env)
- {
- try
- {
- bool ret = this.node.DoRun(this, env);
- List<long> pathList = env.Get<List<long>>(BTEnvKey.NodePath);
- Game.Scene.GetComponent<EventComponent>().Run(EventIdType.BehaviorTreeRunTreeEvent, this, pathList);
- return ret;
- }
- catch (Exception e)
- {
- string source = env.Get<string>(BTEnvKey.BTSource) ?? "";
- Log.Error($"树运行出错, 树名: {this.Discription} 来源: {source}" + e);
- return false;
- }
- }
- }
- }
|