-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSimpleOverlapSphereTask.cs
92 lines (67 loc) · 2.66 KB
/
SimpleOverlapSphereTask.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
using UnityEngine;
using System.Collections.Generic;
namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityPhysics
{
[TaskCategory("Basic/Physics")]
[TaskDescription("Uses an overlap sphere to check for collision, failure if no collision otherwise success-only returns first object hit.")]
public class SimpleOverlapSphereTask : Action
{
[Tooltip("Sphere origin.")]
public SharedGameObject scanOrigin;
[Tooltip("Sphere origin v3.")]
public SharedVector3 scanOriginV3;
[Tooltip("The radius of the shpere.")]
public SharedFloat scanRange;
[Tooltip("Set to true to ignore colliders set to trigger.")]
public SharedBool ignoreTriggerColliders;
[Tooltip("Pick only from these layers.")]
public LayerMask layerMask;
public SharedGameObject hitObject;
public override TaskStatus OnUpdate()
{
if (scanOrigin.Value != null)
{
scanOriginV3.Value = scanOrigin.Value.transform.position;
}
if (ignoreTriggerColliders.Value == true)
{
Collider[] colliders = Physics.OverlapSphere(scanOriginV3.Value, scanRange.Value, layerMask, QueryTriggerInteraction.Ignore);
if (colliders.Length == 0)
{
return TaskStatus.Failure;
} else
{
hitObject.Value = colliders[0].gameObject;
return TaskStatus.Success;
}
} else
{
Collider[] colliders = Physics.OverlapSphere(scanOriginV3.Value, scanRange.Value, layerMask, QueryTriggerInteraction.Collide);
if (colliders.Length == 0)
{
return TaskStatus.Failure;
}
else
{
var list = new List<Collider>(colliders);
for (int index = 0; index < list.Count; index++)
{
var i = list[index].gameObject;
if (i == scanOrigin.Value)
{
list.RemoveAt(index);
}
}
hitObject.Value = list[0].gameObject;
return TaskStatus.Success;
}
}
}
public override void OnReset()
{
scanOriginV3 = Vector3.zero;
hitObject = null;
scanOrigin = null;
}
}
}