forked from mdotstrange/CustomBehaviorDesignerTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverlapSphereToList.cs
83 lines (59 loc) · 2.36 KB
/
overlapSphereToList.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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace BehaviorDesigner.Runtime.Tasks.UnityPhysics
{
[TaskCategory("Basic/Physics")]
[TaskDescription("Casts overlap Sphere and adds hit game objects to a game object list.")]
public class overlapSphereToList : Action
{
[Tooltip("The origin of the sphere")]
public SharedGameObject scanOrigin;
[Tooltip("The radius of the sphere")]
public SharedFloat scanRange;
[Tooltip("The list to store hit game objects in.")]
public SharedGameObjectList listToStoreHitObject;
public LayerMask objectLayerMask = -1;
public SharedBool ignoreTriggerColliders;
public override TaskStatus OnUpdate()
{
listToStoreHitObject.Value.Clear();
float range = scanRange.Value;
if (ignoreTriggerColliders.Value == true)
{
Collider[] colliders = Physics.OverlapSphere(scanOrigin.Value.gameObject.transform.position, range, objectLayerMask, QueryTriggerInteraction.Ignore);
if (colliders.Length == 0)
{
return TaskStatus.Failure;
}
//foreach (Collider col in colliders)
for(int index = 0; index < colliders.Length; index++)
{
var col = colliders[index];
listToStoreHitObject.Value.Add(col.gameObject);
}
}
else
{
Collider[] colliders = Physics.OverlapSphere(scanOrigin.Value.gameObject.transform.position, range, objectLayerMask, QueryTriggerInteraction.Collide);
if (colliders.Length == 0)
{
return TaskStatus.Failure;
}
for (int index = 0; index < colliders.Length; index++)
{
var col = colliders[index];
listToStoreHitObject.Value.Add(col.gameObject);
}
}
return TaskStatus.Success;
}
public override void OnReset()
{
scanOrigin = null;
scanRange = null;
objectLayerMask = -1;
listToStoreHitObject = null;
}
}
}