-
Notifications
You must be signed in to change notification settings - Fork 1
/
BehaviorTreeNode.cs
95 lines (82 loc) · 2.46 KB
/
BehaviorTreeNode.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using UnityEngine;
using System.Collections.Generic;
using System;
/***************************************************************************************
* Title: Behavior Tree
* Author: Stephen Trinh
* Date: 4/28/18
* Code version: 1.0
* Availability: https://github.com/stephentrinh/BehaviorTree
*
***************************************************************************************/
namespace STBehaviorTree
{
public abstract class BehaviorTreeNode
{
protected BehaviorState _currentState;
public string Name;
public List<BehaviorTreeNode> Children;
public BehaviorTreeNode Parent;
public bool DEBUG_on = false;
// Specifically used for displaying the behavior tree
public int ID;
public int Depth;
public bool HasChildren { get { return Children != null && Children.Count > 0; } }
public enum BehaviorState
{
kNone = -1,
kRunning = 0,
kSuccess = 1,
kFailure = 2
}
protected const BehaviorState
STATE_NONE = BehaviorState.kNone,
STATE_RUNNING = BehaviorState.kRunning,
STATE_SUCCESS = BehaviorState.kSuccess,
STATE_FAILURE = BehaviorState.kFailure;
#region Constructors
public BehaviorTreeNode()
{
Children = new List<BehaviorTreeNode>();
}
public BehaviorTreeNode(string name, int depth, int id)
: this()
{
Name = name;
ID = id;
Depth = depth;
}
#endregion
public abstract BehaviorState NodeUpdate(Blackboard blackboard);
public void AddNode(BehaviorTreeNode node)
{
Children.Add(node);
}
public string StateToString(BehaviorState state)
{
switch (state)
{
case STATE_RUNNING:
return "RUNNING";
case STATE_SUCCESS:
return "SUCCESS";
case STATE_FAILURE:
return "FAILURE";
default:
return "NONE";
}
}
public override string ToString()
{
return Name;
}
#region EDITOR ONLY
#if UNITY_EDITOR
public virtual string GetIconPath()
{
return "BehaviorTree/Icons/ICON_BehaviorTreeNode.png";
}
#endif
#endregion
}
}