Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

2,159 views

Published on

Presentation of PhotonWire
https://github.com/neuecc/PhotonWire

Published in: Technology
  • Be the first to comment

Photon Server Deep Dive - View from Implmentation of PhotonWire, Multiplayer Framework for Unity

  1. 1. Work Unity Private https://medium.com/@neuecc http://neue.cc/ @neuecc https://github.com/neuecc/UniRx
  2. 2. Mobile JRPG https://kuro-kishi.jp Unity ASP.NET Photon
  3. 3. Main feature on Game Chat and Notification
  4. 4. Support C#! Can be able to write logic in server Have many cases in Unity
  5. 5. PUN(Photon Unity Network) We don’t use PUN, use Client SDK(with Own Framework)
  6. 6. Getting Started Photon Server
  7. 7. It is class library Execution flow
  8. 8. public class Startup : ApplicationBase { // create connection when connected on server protected override PeerBase CreatePeer(InitRequest initRequest) { if (/* from client request */) { return new MyClientPeer(initRequest); } else // from server request { return new InboundS2SPeer(initRequest); } } protected override void Setup() { // Launching process // Connect to master server var outboundPeer = new OutboundS2SPeer(); outboundPeer.ConnectTcp(); } protected override void TearDown() { // Quitting process } } public class MyClientPeer : ClientPeer { public MyClientPeer(InitRequest initRequest) : base(initRequest) { } protected override void OnOperationRequest(OperationRequest operationRequest, { // byte: operationRequest.OperationCode // Dictionary<byte, object>: operationRequest.Parameters // Send response to client this.SendOperationResponse(new OperationResponse(), sendParameters); } protected override void OnDisconnect(DisconnectReason reasonCode, string reaso { } }
  9. 9. // 1. from Unity to Server var peer = new ClientSidePeer(new MyListener()); peer.OpCustom(opCode: 10, parameter: new Dictionary<byte, object>()); // 2. Receive on Server protected override void OnOperationRequest(OperationRequest operationRequest) { // switch by opCode switch (operationRequest.OperationCode) { case 10: // Parameter from dictionary(<byte, object>) var parameter = operationRequest.Parameters; /* process request */ // 3. Send result to client this.SendOperationResponse(new OperationResponse(operationCode: 5)); break; default: break; } }
  10. 10. // Unity Client public class MyListener : IPhotonPeerListener { // 4. Received from Server public void OnOperationResponse(OperationResponse operationResponse) { // Return response switch (operationResponse.OperationCode) { case 5: // process response break; } } } // 3. Server: Send result to client this.SendOperationResponse(new OperationResponse(operationCode: 5), sendParameters);
  11. 11. // switch by opCode switch (operationRequest.OperationCode) { case 0: break; case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; case 7: break; case 8: break; case 9: break case 10:
  12. 12. // switch by opCode switch (operationRequest.OperationCode) { case 0: break; case 1: break; case 2: break; case 3: break; case 4: break; case 5:
  13. 13. // switch by opCode switch (operationRequest.OperationCo { case 0: break; case 1: break; case 2: break; case 3: break;
  14. 14. Intro to PhotonWire
  15. 15. send byte, Dictionary and switch and switch Can not track send-receive message
  16. 16. Typed Asynchronous RPC Layer https://github.com/neuecc/PhotonWire
  17. 17. Windows Client
  18. 18. Server to Server
  19. 19. Next PhotonWire
  20. 20. DESERIALIZE SPEED Replacing serializer
  21. 21. (De)serialize is slow in Unity ScriptableObject > JsonUtility > *** > MsgPack > XxxJSON
  22. 22. New WireFormat which does not Deserialize Fit to C# and Unity Will be available soon

×