DI / IoC using PUN
The whole answer can be found below.
Try Our
Documentation
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.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
DI / IoC using PUN
ChaosHelme
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.
Thx
Comments
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.
ChaosHelme
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.
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!
ChaosHelme
2017-04-11 16:42:57
Thanks :)
Back to top