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)
    {
    }
 public void StartNewRtSession(RtSessionInfo info,
                               OnPlayerConnectedToGame onPlayerConnectedToGame,
                               OnPlayerDisconnected onPlayerDisconnected,
                               OnRTReady onRtReady,
                               OnPacketReceived onPacketReceived)
 {
     GameSparksController.Instance().GetGameSparksFactory().StartNewRtSession(
         info,
         onPlayerConnectedToGame,
         onPlayerDisconnected,
         onRtReady,
         onPacketReceived,
         ref _sessionInfo,
         ref _gameSparksRtUnity
         );
 }
Ejemplo n.º 3
0
    public void Init(SceneManager sceneManager, RtSessionInfo tempRTSessionInfo)
    {
        _sceneManager = sceneManager;

        ChatPanelToggle    = _sceneManager.Game.scope["ChatPanelToggle"].GetComponent <Button>();
        ChatPanelToggleOff = _sceneManager.Game.scope["ChatPanelToggleOff"].GetComponent <Button>();

        ChatPanelToggleText    = _sceneManager.Game.scope["ChatPanelToggleText"].GetComponent <Text>();
        ChatPanelToggleOffText = _sceneManager.Game.scope["ChatPanelToggleOffText"].GetComponent <Text>();

        ChatPanel       = _sceneManager.Game.scope["ChatPanel"];
        sendMessageBttn = _sceneManager.Game.scope["SendChatButton"].GetComponent <Button>();
        messageInput    = _sceneManager.Game.scope["ChatInputField"].GetComponent <InputField>();
        chatLogOutput   = _sceneManager.Game.scope["ChatContent"].GetComponent <Text>();

        GameSparksRTController.Instance().StartNewRtSession(
            tempRTSessionInfo,
            OnPlayerConnectedToGame,
            OnPlayerDisconnected,
            OnRTReady,
            OnPacketReceived
            );

        ChatPanelToggle.onClick.AddListener(() =>
        {
            ChatPanelToggle.gameObject.SetActive(false);
            ChatPanel.SetActive(true);
        });

        ChatPanelToggleOff.onClick.AddListener(() =>
        {
            ChatPanelToggle.gameObject.SetActive(true);
            ChatPanel.SetActive(false);
        });

        sendMessageBttn.onClick.AddListener(SendMessage);

        chatLogOutput.text = string.Empty; // we want to clear the chat log at the start of the game in case there is any debug text in there
    }
Ejemplo n.º 4
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
    }