Ejemplo n.º 1
0
    /*------------------------------------------------------------------------------------------------------------------------------------------------------
     * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     * * -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     *
     *                                                                              REALTIME
     *
     * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

    public void StartNewRtSession(RtSessionInfo info,
                                  GameSparksRTController.OnPlayerConnectedToGame onPlayerConnectedToGame,
                                  GameSparksRTController.OnPlayerDisconnected onPlayerDisconnected,
                                  GameSparksRTController.OnRTReady onRtReady,
                                  GameSparksRTController.OnPacketReceived onPacketReceived,
                                  ref RtSessionInfo sessionInfo, ref GameSparksRTUnity gameSparksRtUnity)
    {
    }
Ejemplo n.º 2
0
    /*------------------------------------------------------------------------------------------------------------------------------------------------------
     * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     * -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     * * -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     *
     *                                                                              REALTIME
     *
     * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/

    public void StartNewRtSession(RtSessionInfo info,
                                  GameSparksRTController.OnPlayerConnectedToGame onPlayerConnectedToGame,
                                  GameSparksRTController.OnPlayerDisconnected onPlayerDisconnected,
                                  GameSparksRTController.OnRTReady onRtReady,
                                  GameSparksRTController.OnPacketReceived onPacketReceived,
                                  ref RtSessionInfo sessionInfo,
                                  ref GameSparksRTUnity gameSparksRtUnity)
    {
        DebugTool.Instance().SetMessage(new DebugMessage("GSM| Creating New RT Session Instance...", DebugMessageType.Message));
        sessionInfo       = info;
        gameSparksRtUnity = this.gameObject.AddComponent <GameSparksRTUnity>(); // Adds the RT script to the game
        // In order to create a new RT game we need a 'FindMatchResponse' //
        // This would usually come from the server directly after a successful MatchmakingRequest //
        // However, in our case, we want the game to be created only when the first player decides using a button //
        // therefore, the details from the response is passed in from the gameInfo and a mock-up of a FindMatchResponse //
        // is passed in. //
        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", (double)info.GetPortID())
                                       .AddString("host", info.GetHostURL())
                                       .AddString("accessToken", info.GetAccessToken()); // construct a dataset from the game-details

        FindMatchResponse response = new FindMatchResponse(mockedResponse);              // create a match-response from that data and pass it into the game-config

        // So in the game-config method we pass in the response which gives the instance its connection settings //
        // In this example, I use a lambda expression to pass in actions for
        // OnPlayerConnect, OnPlayerDisconnect, OnReady and OnPacket actions //
        // These methods are self-explanatory, but the important one is the OnPacket Method //
        // this gets called when a packet is received //

        gameSparksRtUnity.Configure(response,
                                    (peerId) => { onPlayerConnectedToGame(peerId); },
                                    (peerId) => { onPlayerDisconnected(peerId); },
                                    (ready) => { onRtReady(ready); },
                                    (packet) => { onPacketReceived(packet); });
        gameSparksRtUnity.Connect(); // when the config is set, connect the game
    }