Question Creating re-useable & versatile Triggers

SupremeGrandRuler

New member
Joined
Apr 21, 2015
Messages
1
Programming Experience
Beginner
I'm trying to create Triggers--an object that can be subscribed to an event, and when the event subscribed to is fired, the trigger checks a set of conditions and if the conditions are met, executes a set of actions.
My goals for the trigger:
- Arguments passed on (if any) to the condition & actions should be based on information from the event the trigger is subscribed to and/or the object the trigger is attached to
- Trigger should be as flexible as possible: creating tons of classes for the conditions & actions does not appeal too much to me,

Subscribing to an event is easy enough but it's what to do after that I'm a little stuck on.
First off, I am using the Unity Engine which uses a subset of .NET 3.5.
My first thought was to use Generics & Delegates but the way I coded it made it quite complicated: A generic for the event, 0-2 generic parameters for the predicate (no condition, event condition, or event + container object condition), and then 0+ generic parameters for each parameter accepted by the actions (then also came the trouble on how I can pass on the necessary info from the event / container to the actions). This means I would have to create many, many versions of the trigger.

Does anyone have any advice or tips on achieving this?
 
Top Bottom