Generic Trigger
The triggers used by the level designers. Their effects were defined throughout the production.
ITS PROPERTIES

1
2
{
3
5
4
{
6
7
{
8
{
9
10
11
{
12
-
Behaviour
-
Once Only : does the action only once.
-
Multiple : does the actions everytime
-
-
Direction
-
Any : from any direction
-
Specific : only the front or the back of the trigger is active.
-
-
The trigger's side that are active. Are both enabled if Direction (2) is set to Any.
-
Only Player As Agent : if enabled, the list of Agents will automatically filled with only the Avatar on start.
-
Trigger For (useful if there's more than one agent)
-
First Agent Only : activate when one of the agents enters/exits the trigger
-
Each Agent : activates when all agents enter/exits the trigger.
-
-
Agents : the list of agents (objects that activates the trigger)
-
Triggered Objects (list of all the objects that are affected when the trigger is activating)
-
Delay : delay in seconds before the effect is made.
-
Delay on Enter/Exit : applies the delay for the onEnter/onExit actions only (or both).
-
Obj : is the object on which the action is made.
-
Effect : What action is done on the "obj" (10)
Note :
-
"Agent" is an object that activates the trigger.
-
"Effect" is the action of the trigger
-
"Triggered Object" is the objects on which the trigger does the action.
12 .
The user decides which action to take for each event :
-
onEnter : when the agent enters the trigger
-
onStay : when the agent stays in the trigger
-
onExit : when the agent exits the trigger
The actions are :
-
Activate : activates the effect.
For example, with Effect_Open, it'll open the obj. -
Deactivate : deactivates the effect.
For example with Effect_Open, it'll close the obj. -
Nothing : does nothing
The actions can be defined differently for each side of the trigger (front and back).
HOW TO DEFINE THE EFFECTS (TRIGGER ACTIONS)


The challenge was to make the effects (actions) independable of the triggered objects, meaning you could use every effects on every triggerable objects.
For that purpose, I defined two types of variables to store in my GenericTrigger script :
-
IsTriggerable : is the object to trigger. Every triggerable objects needs the IsTriggerable script.
-
EffectList : is the Effect used on the object. EffectList is the parent of all effects so they could all be stored in the same list.

-
"Triggered" is the function called when the action is set to "Activate"
(see the Trigger's Inspector)
For example, Triggered (Effect_Open) will open the door. -
"Untriggered" is the function called when the action is set to "Deactivate"
(see the Trigger's Inspector)
For example, UnTriggered (Effect_Open) will close the door.
Notice that the parameter for both these functions is the Effect of the Trigger.
These two variables are stored in the GenericTrigger via a defined serialized class.
Now that we got the TriggeredObject and the Effect stored inside the GenericTrigger, we have to apply the Effect to the TriggeredObject once the trigger activates. However, an Effect might not have the same behaviour on different objects (for example Effect_Open on a Door VS Effect_Open on a Window).
Therefore, the actions for every Effect had to be defined within each TriggeredObjects script. In other words, the action of Effect_Open would be defined within both the Door and Window scripts. It was then possible to write two different code for both these objects for the same Effect.
To force each programmer to define the functions necessary, every triggerable objects had to implement the interface ITriggerable. That way, every triggerable objects would have a dedicated function once they've been triggered. That's inside these functions that we customize their behaviours.

Once a function implements ITriggerable, we can customize the code for Every effects within the object. In this example, the triggerable object is Door.
The interface's functions are defined within Door. These functions are :
-
Triggered (EffectList)
-
UnTriggered (EffectList)
Door implements ITriggerable
The last thing we need is for the GenericTrigger to reach these functions while passing the effect.
A generic path was made.
-
GenericTrigger script calls the function "Activate(EffectList)", or its counterpart (Deactivate) within IsTriggerable.
2. The code reaches Triggered and UnTriggered via SendMessage. The function
should exist for each triggerable objects that implements ITriggerable.
Since an EffectList is passed as a parameter, the function GetType() is used to further know about which effect is used.


}
IsTriggerable and EffectList
Remember that IsTriggerable is attached to each triggerable objects and is the type of variable stored inside GenericTrigger for the TriggeredObjects. Since the effect is also stored inside the script, the GenericTrigger can easily passes the effect.