How To Emit / Raise Events

JulyForTodayJulyForToday USMember
edited September 2016 in UrhoSharp

Firstly, I'm having some trouble trying to subscribe to events. Inside my application class I have something like this:
Engine.SubscribeToEvent(new StringHash("TestEvent"), ???);

The prototype is SubscribeToEvent(StringHash eventType, IntPtr handler). But I'm not sure how to pass it a pointer to a callback function. Googling around has gotten me too far, and I couldn't find any thing to go on in UrhoSharp's source, or in the samples, or documentation here on the site. I don't know if it's me being dense, but I can't seem to figure this out.

Likewise, I can't seem to find anything at all about actually raising/emitting the event in the first place.

Answers

  • EgorBoEgorBo BYXamarin Team ✭✭✭

    All events are strong typed. So instead of SubscribeToEvent("Update") you can subscribe to the Update event via this.Update += . You don't need to use SubscribeToEvent(StringHash) generic signature.

  • GlebLebedevGlebLebedev IEMember ✭✭

    I need to communicate between components in the node. Is there a way to subscribe for an event as in Urho3D?

  • EgorBoEgorBo BYXamarin Team ✭✭✭

    Custom events were added in commit https://github.com/xamarin/urho/commit/15159e79ca8c4997bb4a3283330867c28f99da59
    Syntax:
    obj.SubscribeToEvent("SomeCustomEvent", args => ...);

  • FastranFastran ITMember

    Is it possible to define a data payload to send with a custom event like the Urho3D void Object::SendEvent(StringHash eventType, VariantMap& eventData) ?

Sign In or Register to comment.