The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

DI / IoC using PUN

2017-04-05 12:59:57

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.



2017-04-05 14:33:49

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)  

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.

2017-04-05 16:19:25

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.

2017-04-09 06:10:48

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!

2017-04-11 16:42:57

Thanks :)

Back to top