Пример #1
0
    private void SendMessage()
    {
        if (messageInput.text != string.Empty)
        { // first check to see if there is any message to send
          // for all RT-data we are sending, we use an instance of the RTData object //
          // this is a disposable object, so we wrap it in this using statement to make sure it is returned to the pool //
            using (RTData data = RTData.Get())
            {
                data.SetString(1, messageInput.text);                            // we add the message data to the RTPacket at key '1', so we know how to key it when the packet is receieved
                data.SetString(2, DateTime.Now.ToString());                      // we are also going to send the time at which the user sent this message

                UpdateChatLog("Me", messageInput.text, DateTime.Now.ToString()); // we will update the chat-log for the current user to display the message they just sent

                messageInput.text = string.Empty;                                // and we clear the message window

                DebugTool.Instance().SetMessage(new DebugMessage("Sending Message to All Players... \n" + messageInput.text, DebugMessageType.Error));

                // for this example we are sending RTData, but there are other methods for sending data we will look at later //
                // the first parameter we use is the op-code. This is used to index the type of data being send, and so we can identify to ourselves which packet this is when it is received //
                // the second parameter is the delivery intent. The intent we are using here is 'reliable', which means it will be send via TCP. This is because we aren't concerned about //
                // speed when it comes to these chat messages, but we very much want to make sure the whole packet is received //
                // the final parameter is the RTData object itself //
                GameSparksRTController.Instance().GetRtSession().SendData(1, GameSparks.RT.GameSparksRT.DeliveryIntent.RELIABLE, data);
            }
        }
        else
        {
            DebugTool.Instance().SetMessage(new DebugMessage("Not Chat Message To Send...", DebugMessageType.Error));
        }
    }
Пример #2
0
    public void OnMessageReceived(RTPacket _packet)
    {
        Debug.Log(_packet.Data.GetString(1));

        foreach (RtSessionInfo.RTPlayer player in GameSparksRTController.Instance().GetSessionInfo().GetPlayerList())
        {
            if (player.peerId == _packet.Sender)
            {
                // we want to get the message and time and print those to the local users chat-log //
                UpdateChatLog(player.displayName, _packet.Data.GetString(1), _packet.Data.GetString(2));
            }
        }
    }
Пример #3
0
    public void SetupChatPanel()
    {
        ChatPanelToggle.gameObject.SetActive(true);

        string userName = "******";

        foreach (RtSessionInfo.RTPlayer player in GameSparksRTController.Instance().GetSessionInfo().GetPlayerList())
        {
            if (player.peerId != GameSparksRTController.Instance().GetRtSession().PeerId.Value)
            {
                userName = player.displayName;
            }
        }

        ChatPanelToggleText.text    = userName;
        ChatPanelToggleOffText.text = userName;
    }
Пример #4
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
    }