OnlyNPC:Part1
This commit is contained in:
44
Assets/Scripts/AI NPC/BehavourTreeCore.cs
Normal file
44
Assets/Scripts/AI NPC/BehavourTreeCore.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum NodeState
|
||||
{
|
||||
Success, Failure, Running
|
||||
}
|
||||
|
||||
public abstract class Node
|
||||
{
|
||||
protected NodeState state;
|
||||
public NodeState State => state;
|
||||
public abstract NodeState Evaluate();
|
||||
}
|
||||
|
||||
public class Selector : Node
|
||||
{
|
||||
protected List<Node> nodes = new List<Node>(); // children nodes
|
||||
|
||||
public Selector(List<Node> nodes)
|
||||
{
|
||||
this.nodes = nodes;
|
||||
}
|
||||
|
||||
public override NodeState Evaluate()
|
||||
{
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
switch (node.Evaluate())
|
||||
{
|
||||
case NodeState.Failure:
|
||||
continue;
|
||||
case NodeState.Success:
|
||||
state = NodeState.Success;
|
||||
return state;
|
||||
case NodeState.Running:
|
||||
state = NodeState.Running;
|
||||
return state;
|
||||
}
|
||||
}
|
||||
state = NodeState.Failure;
|
||||
return state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user