Game Development Reference
In-Depth Information
This is optional, of course, and you can still do your own thing if you
are so inclined. However, a lot of thought went into the current event
framework that Unity has built, so it's worth considering.
To build your own event, you will need to define the following:
• A custom event data structure (extending from BaseEventData ).
• An interface for the custom event (extending from IEventSystemHandler ).
• A static container class containing the Execute functions.
• ( Optional ) An Input module (extending from BaseInputModule ) to process
and execute your events. This could be done from anywhere, however.
• A class or GameObject that implements your interface (covered previously).
This sounds like a lot, but in reality it really is (just kidding)!
The main reason you would want to build your own events is to manage things
going on in your game world that other objects need to know about, such as:
• An alarm system alerting all droids to swarm in
• Targeting data, to tell your starships to attack a certain point
• A conversation or event log system, where several parties needs to feed data
in to be displayed
If we take the first example, let's walk through setting up our custom event handler.
An alarm system is a great fit for this, especially with an Input Manager that
monitors all cameras and sends all the droids if one detects something. (I really like
this idea, as it could open up possibilities of hacking cameras to prevent the alarm
being raised.)
A custom event Data Structure
When planning your custom event, the cornerstone is what data you consider
to be important when this event fires. In the built-in interfaces, this can include
information such as which GameObject is being affected, the mouse cursor
position, and so on.
To start off, we'll create a new C# script to put all this code into one file, just so it's
readable. To fully implement it, however, you would need an actual game to wrap
around it. The main aim here is to set you on the path.
 
Search WWH ::




Custom Search