- Home /
How to do a "custom" callback ? (like OnMouseEnter())
Hello there !
I work in C# and I want to implement a custom callback for pointer events, so that it works for any camera, any kind of object, any king of devices (both Touch and Mouse). What I'm having problem with is not the logic itself. I implemented an observer pattern using an interface for objects supposed to receive those events (with methods like OnPointingDeviceEnter, OnPointingDeviceExit ...)
But it's quite boring to ask the user to implement each of those method even though he might want to use only one of those. Plus, I would like to keep it simple for the user, so I'd prefer not to require him to register delegates for each events.
Is there a way not to use any of the aforementioned methods ? How are MonoBehaviour callbacks implemented since users don't even have to override Update(), Start(), ... ?
Thanks in advance for your answers !
Answer by whydoidoit · Jun 20, 2013 at 11:08 AM
Effectively they are done like "SendMessage" though faster.
My article here: http://unitygems.com/fsm2/ covers something that lets you do a faster version that uses reflection only on configuration and after is pretty much the same speed as a normal method call, no need for implementation of interfaces etc.
Sounds like just what I'm looking for. Plus, it will be the perfect time to give reflection a try. I'll go for your solution !
Thank you both ! :)
Answer by Glurth · Mar 04, 2015 at 08:08 PM
I did it this way. No messages or broadcasts needed. http://forum.unity3d.com/threads/how-to-select-a-callback-function-for-your-script-from-the-editor.295550/
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
PropertyDrawer, Change property within callback 2 Answers
Distribute terrain in zones 3 Answers
Calling C# methods from jslib 0 Answers
Assign Event Trigger of object from another object in script 1 Answer