Callbacks system

Hi,

Actually my question is not really about any way to handle photon but I would like to know how you developped events like OnConnectedToPhoton.

It is like a callback or an event but without any need to subscribe to it first. I would like to know how to implement this if you mind sharing :D

Comments

  • I think you are talking about the Photon Unity Networking package for Unity3d? If so: Just have a look :)
    In this case, we actually didn't implement the call ourselves but used SendMonoMessage implemented by Unity. I think it's some variation of Invoke(), which is part of the DotNet framework.
  • I was guessing you'd have implemented something specific because SendMessage is known to be slow and expensive cpu-wise. I was thinking about something more like Update, Awake, Start etc, from Unity, and I don't know how those work behind. Calling an Update using SendMessage would not be much efficient if called every frame.
  • I guess Update and SendMessage work much the same but they cache all the MethodInfo instances they need to call Update regularly. This is something they can't really do when calling arbitrary named methods in SendMonoMessage though.
    Example: We cache the OnSerializePhotonView methods we have to call often but we don't cache the instances of classes for the other callbacks we rarely do.