-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathBehavior.cs
More file actions
76 lines (68 loc) · 1.98 KB
/
Behavior.cs
File metadata and controls
76 lines (68 loc) · 1.98 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using BehaviorLibrary.Components;
using BehaviorLibrary.Components.Composites;
namespace BehaviorLibrary
{
public enum BehaviorReturnCode
{
Failure,
Success,
Running
}
public delegate BehaviorReturnCode BehaviorReturn();
/// <summary>
///
/// </summary>
public class Behavior
{
private RootSelector b_Root;
private BehaviorReturnCode b_ReturnCode;
public BehaviorReturnCode ReturnCode
{
get { return b_ReturnCode; }
set { b_ReturnCode = value; }
}
/// <summary>
///
/// </summary>
/// <param name="root"></param>
public Behavior(RootSelector root)
{
b_Root = root;
}
/// <summary>
/// perform the behavior
/// </summary>
public BehaviorReturnCode Behave()
{
try
{
switch (b_Root.Behave())
{
case BehaviorReturnCode.Failure:
ReturnCode = BehaviorReturnCode.Failure;
return ReturnCode;
case BehaviorReturnCode.Success:
ReturnCode = BehaviorReturnCode.Success;
return ReturnCode;
case BehaviorReturnCode.Running:
ReturnCode = BehaviorReturnCode.Running;
return ReturnCode;
default:
ReturnCode = BehaviorReturnCode.Running;
return ReturnCode;
}
}
catch (Exception e)
{
#if DEBUG
Console.Error.WriteLine(e.ToString());
#endif
ReturnCode = BehaviorReturnCode.Failure;
return ReturnCode;
}
}
}
}