예제 #1
0
    public void GameChatConnect(string userName)
    {
        bool tryConnect = false;

        if (this.chatClient == null)
        {
            tryConnect = true;
        }
        else
        {
            if (this.chatClient.State != ChatState.ConnectedToFrontEnd &&
                this.chatClient.State != ChatState.ConnectingToFrontEnd &&
                this.chatClient.State != ChatState.ConnectedToNameServer &&
                this.chatClient.State != ChatState.ConnectingToNameServer)
            {
                tryConnect = true;
            }
            Debug.Log("GameChatConnect state: " + this.chatClient.State);
        }
        if (tryConnect)
        {
            nowConnecting    = true;
            chatDisconnected = false;
            this.chatClient  = new ChatClient(this);
            ExitGames.Client.Photon.Chat.AuthenticationValues authVals =
                new ExitGames.Client.Photon.Chat.AuthenticationValues(userName);
            authVals.AuthType = ExitGames.Client.Photon.Chat.CustomAuthenticationType.Custom;
            localPlayerId     = ZPlayerPrefs.GetString("playfabId");
            authVals.AddAuthParameter("username", localPlayerId);
            authVals.AddAuthParameter("token", ZPlayerPrefs.GetString("token"));

            this.chatClient.AuthValues = authVals;
            this.chatClient.ChatRegion = "EU";
            Debug.Log("Connect chat user: "******", id: " + localPlayerId + ", token: " + ZPlayerPrefs.GetString("token"));
            this.chatClient.Connect(PhotonNetwork.PhotonServerSettings.ChatAppID, MainMenu.GameVersion, authVals);
        }
        else
        {
            Debug.LogWarning("Chat already connected");
        }
    }