-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlackboard.cs
84 lines (70 loc) · 1.7 KB
/
Blackboard.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BeeTree {
public class Blackboard
{
//List<>
private BehaviourController _controller;
private Dictionary<string, object> _variables;
public BehaviourController BehaviourController
{
get { return _controller; }
}
public Blackboard(BehaviourController controller)
{
_controller = controller;
_variables = new Dictionary<string, object>();
}
public void SetVariable(string name, object value)
{
if (name == null)
{
throw new System.Exception("BehaviourTree.GetVariable: variable name cannot be null.");
}
if (_variables.ContainsKey(name))
{
_variables[name] = value;
}
else
{
_variables.Add(name, value);
}
}
public object GetVariable(string name)
{
if (name == null)
{
throw new System.Exception("Blackboard.GetVariable: variable name cannot be null.");
}
if (_variables.ContainsKey(name))
{
return _variables[name];
}
else
{
throw new System.Exception("Blackboard.GetVariable: Cannot find variable: " + name);
}
}
public bool HasVariable(string name)
{
if (name == null)
{
throw new System.Exception("Blackboard.HasVariable: variable name cannot be null.");
}
return _variables.ContainsKey(name);
}
public void DeleteVariable(string name)
{
if (name == null)
{
throw new System.Exception("Blackboard.GetVariable: variable name cannot be null.");
}
if (!_variables.ContainsKey(name))
{
throw new System.Exception("Blackboard.DeleteVariable: cannot delete variable, it doesn't exist: " + name);
}
_variables.Remove(name);
}
}
}