-
Notifications
You must be signed in to change notification settings - Fork 3
/
triggerEventStoreHitObject.cs
105 lines (86 loc) · 3.18 KB
/
triggerEventStoreHitObject.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
93
94
95
96
97
98
99
100
101
102
103
104
105
// (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
using System;
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Detect collisions with objects that have RigidBody components. \nNOTE: The system events, TRIGGER ENTER, TRIGGER STAY, and TRIGGER EXIT are sent when any object collides with the trigger. Use this action to filter collisions by Tag.")]
public class TriggerEventStoreHitObject : FsmStateAction
{
[Tooltip("The type of trigger event to detect.")]
public TriggerType trigger;
[UIHint(UIHint.Tag)]
[Tooltip("Filter by Tag.")]
public FsmString collideTag;
[Tooltip("Event to send if the trigger event is detected.")]
public FsmEvent sendEvent;
[UIHint(UIHint.Variable)]
[Tooltip("Store the GameObject that collided with the Owner of this FSM.")]
public FsmGameObject storeCollider;
public FsmGameObject hitObject;
public override void Reset()
{
trigger = TriggerType.OnTriggerEnter;
collideTag = "Untagged";
sendEvent = null;
storeCollider = null;
}
public override void OnPreprocess()
{
switch (trigger)
{
case TriggerType.OnTriggerEnter:
Fsm.HandleTriggerEnter = true;
break;
case TriggerType.OnTriggerStay:
Fsm.HandleTriggerStay = true;
break;
case TriggerType.OnTriggerExit:
Fsm.HandleTriggerExit = true;
break;
}
}
void StoreCollisionInfo(Collider collisionInfo)
{
storeCollider.Value = collisionInfo.gameObject;
hitObject.Value = Fsm.TriggerCollider.gameObject;
}
public override void DoTriggerEnter(Collider other)
{
if (trigger == TriggerType.OnTriggerEnter)
{
if (other.gameObject.tag == collideTag.Value)
{
StoreCollisionInfo(other);
Fsm.Event(sendEvent);
}
}
}
public override void DoTriggerStay(Collider other)
{
if (trigger == TriggerType.OnTriggerStay)
{
if (other.gameObject.tag == collideTag.Value)
{
StoreCollisionInfo(other);
Fsm.Event(sendEvent);
}
}
}
public override void DoTriggerExit(Collider other)
{
if (trigger == TriggerType.OnTriggerExit)
{
if (other.gameObject.tag == collideTag.Value)
{
StoreCollisionInfo(other);
Fsm.Event(sendEvent);
}
}
}
public override string ErrorCheck()
{
return ActionHelpers.CheckOwnerPhysicsSetup(Owner);
}
}
}