-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathGetGameObjectOtherTree.cs
62 lines (51 loc) · 1.75 KB
/
GetGameObjectOtherTree.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
using UnityEngine;
using System.Collections;
namespace BehaviorDesigner.Runtime.Tasks.Custom
{
[TaskDescription("Gets a game object var on another tree defined by sharedGameObject")]
public class GetGameObjectOtherTree : Action
{
public SharedGameObject sharedGameObject;
public SharedInt group;
public string variableName;
public SharedGameObject targetVariable;
private Behavior behavior;
public override void OnStart()
{
var behaviorTrees = GetDefaultGameObject(sharedGameObject.Value).GetComponents<Behavior>();
if (behaviorTrees.Length == 1)
{
behavior = behaviorTrees[0];
} else if (behaviorTrees.Length > 1)
{
for (int i = 0; i < behaviorTrees.Length; ++i)
{
if (behaviorTrees[i].Group == group.Value)
{
behavior = behaviorTrees[i];
break;
}
}
}
// If the group can't be found then use the first behavior tree
if (behavior == null)
{
behavior = behaviorTrees[0];
}
}
public override TaskStatus OnUpdate()
{
if (behavior == null)
{
return TaskStatus.Failure;
}
targetVariable.Value = (behavior.GetVariable(variableName) as SharedGameObject).Value;
return TaskStatus.Success;
}
public override void OnReset()
{
variableName = "";
targetVariable = null;
}
}
}