예제 #1
0
 void Awake()
 {
     facts = new Dictionary <string, float>();
     // Add blackboard variables here such as
     // facts.Add("Thirst", 100.0f);
     BlackboardManager.AddBlackboard(this);
 }
 /*
  * Executes all responses of the event that was just finished
  */
 public void ExecuteResponses()
 {
     if (currentEvent != null)
     {
         foreach (EventResponse response in currentEvent.responses)
         {
             BlackboardManager.Respond(response);
         }
     }
 }
예제 #3
0
    /*
     * Can this event be executed
     */
    public bool CanExecute()
    {
        // Each requirement must pass to be executed
        bool canExecute = true;

        foreach (EventRequirement requirement in requirements)
        {
            if (!BlackboardManager.Compare(requirement))
            {
                return(false);
            }
        }
        return(canExecute);
    }
예제 #4
0
 // Add this blackboard to the manager
 private void Start()
 {
     BlackboardManager.AddBlackboard(this);
 }
예제 #5
0
        public static void LoadGraph(SerializedGraph graph, BehaviourTree behaviourTree, BlackboardManager bbManager)
        {
            EntryTask graphEntry            = null;
            Dictionary <string, Task> tasks = new Dictionary <string, Task>();

            for (int i = 0; i < graph.Nodes.Count; i++)
            {
                var  serializedNode = graph.Nodes[i];
                Type behaviourType  = serializedNode.NodeRuntimeType;

                if (behaviourType == typeof(EntryTask))
                {
                    graphEntry = Activator.CreateInstance <EntryTask>();
                    tasks.Add(serializedNode.Guid, graphEntry);
                }
                else
                {
                    var task = (Task)JsonUtility.FromJson(graph.Nodes[i].NodeJSONData, behaviourType);//(Task)Activator.CreateInstance(behaviourType);
                    tasks.Add(serializedNode.Guid, task);
                    bbManager.BindTask(behaviourTree, task);
                }
            }

            for (int i = 0; i < graph.Edges.Count; i++)
            {
                var serializedEdge = graph.Edges[i];

                Debug.Log($"{serializedEdge.SourceNodeGUID} ---> {serializedEdge.TargetNodeGUID}");

                Task source = tasks[serializedEdge.SourceNodeGUID];
                Task target = tasks[serializedEdge.TargetNodeGUID];

                if (source is EntryTask)
                {
                    EntryTask entry = (EntryTask)source;
                    entry.TreeRoot = target;
                }
                else if (source is Composite)
                {
                    Composite composite = (Composite)source;
                    composite.AddChild(target);
                }
                else if (source is Decorator)
                {
                    Decorator decorator = (Decorator)source;
                    decorator.Decoratee = target;
                }
            }
            behaviourTree.Root = graphEntry;
        }