Forum rules - please read before posting.

EventManager - Adding custom events

edited July 25 in Technical Q&A

Hi

My game has a Time of Day manager script which handles when/how to advance time. Certain objects need to be notified when TOD events happen (advance, new day, etc).

I can easily write my own event manager to do this.

However I feel like i should integrate this into the AC Event Manager so that

  1. I dont have multiple event manager systems (not positive on this one, might be better to keep seperate)
  2. Action lists and be triggered on events via the Events Editor
  3. Probably more

Notes:

  • I could easily add appropriate delegates and events/methods directly to EventManager.cs but I would prefer not to modify the core AC code base as it will make updating difficult.
  • It would be nice if I could subclass EventManager to have my own, but a (quick) glance makes me think its not setup this way? Can I have a derived event manager that inherits from EventManager?
  • I would like to expose these events so that an action list can be called via the Events Editor.

Is this possible/what do you recommend?

Thanks :)

Comments

  • edited July 25

    Update: After looking into how the events editor GUI is populated I see that you use reflection to find all BaseEvent derived classes in all assemblies which is then used to populate the dropdown list.

    This is slick, well done.

    So I'm going to use my own event manager for my game specific events; keeping them separate from AC events.

    Then - for any of those events that I want exposed to the editor, I'll create my own derived BaseEvent class (that subscribes to my event and calls Run when it is fired)

    And: I see you support custom parameters to be passed to the action list based on the class; even slicker :)

    If I missing something let me know, but this works quite well imo.

    Minor: Are there docs on this (beyond the class documentation)? If so I couldn't find with reasonable searching (granted its a pretty advanced topic for most AC users, I suspect)

  • Good finding!

    No, I'm afraid it's not a documented feature - in all honesty, it wasn't built with user-extension like this too much in mind. But with the reflection approach, it should be possible.

    You can check out the built-in EventBase subclasses to get a feel for what's needed, but essentially:

    • Override the Register / Unregister functions to subscribe/unsubscribe from your event
    • To run the ActionList, call the Run function, passing in your parameters as an object array
    • Implement GetParameterReferences and return an array of the same value/order as the above
    • Implement HasConditions / ShowConditionGUI to expose fields in the Editor
  • edited July 26

    Yea, I did all this yesterday - it worked well in my first test case. Thanks!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.