DI / IoC using PUN
Options
Hello everybody,
I was wondering if it is possible to use Photon with any IoC Framework (i.e. Zenject) when it comes to the Photon initialisiation?
Does anybody has expirience in using these two packages?
I really would love to have an IoC Framework in my PUN-based project.
Thx
I was wondering if it is possible to use Photon with any IoC Framework (i.e. Zenject) when it comes to the Photon initialisiation?
Does anybody has expirience in using these two packages?
I really would love to have an IoC Framework in my PUN-based project.
Thx
0
Best Answer
-
Ahh, I didn't know that, but then again, most of my platforms have been PC, Android, iPhone. The same idea applies though. You could create a service class that you would inject, which implements IPunCallbacks.
Then intercept photon events only once, on this service, and dispatch your own signals, based on what you want to do with that data.
Usually, I just pass them straight on through, but you could parse the data first, and raise game specific events instead.
Then any class you can inject into, just listens for your game signals, and handles the data as needed.
Just as a quick example, you could handle OnPhotonPlayerPropertiesChanged in this service, find out what properties have been changed, then dispatch game events, like 'EquipWeaponSignal', or 'EquipArmorSignal', etc. Then your WeaponManager or EquipmentManager would have listeners for these events, instead of the core 'OnPhotonPlayerPropertiesChanged' event...
Just an idea, good luck man!
5
Answers
-
I'm using StrangeIOC with PUN, however we've come up with our own 'StrangePackage' system, which is similar, but a little different than the typical Context architecture. It works great though. I basically just have a class that implements IPunCallbacks, and for each callback I want to listen to, I have a signal that dispatches with any data needed, for example:
public void OnPhotonPlayerConnected(PhotonPlayer newPlayer) { PhotonPlayerConnectedSignal.Dispatch(newPlayer); }
Then if I need a command, I just bind that to the signal, or I just addListener to it if it is one of those fire and forget signals.0 -
Hey Bunzaga thanks for the answer.
The problem we're seeing in StrangeIoC is the combability. According to the GitHub page it's not running on Xbox One and PS4. Our game is suppose to be released on these plattforms as well.0 -
Ahh, I didn't know that, but then again, most of my platforms have been PC, Android, iPhone. The same idea applies though. You could create a service class that you would inject, which implements IPunCallbacks.
Then intercept photon events only once, on this service, and dispatch your own signals, based on what you want to do with that data.
Usually, I just pass them straight on through, but you could parse the data first, and raise game specific events instead.
Then any class you can inject into, just listens for your game signals, and handles the data as needed.
Just as a quick example, you could handle OnPhotonPlayerPropertiesChanged in this service, find out what properties have been changed, then dispatch game events, like 'EquipWeaponSignal', or 'EquipArmorSignal', etc. Then your WeaponManager or EquipmentManager would have listeners for these events, instead of the core 'OnPhotonPlayerPropertiesChanged' event...
Just an idea, good luck man!
5 -
Thanks0