簡體   English   中英

為什么PUN不提供回調? ProtonNetworking無法正常工作

[英]Why PUN is not giving callbacks? ProtonNetworking is not working as expected

我正在嘗試通過PUN進行簡單的操作,只需連接到主服務器,然后加入隨機房間即可。 我已將所有信息設置為登錄到控制台,據我了解,我已連接到服務器,但從未調用過OnConnectedToMaster。

 using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
     using Photon;
 public class  RandomMatchmakera : Photon.PunBehaviour {

/// <summary>
/// MonoBehaviour method called on GameObject by Unity during early initialization phase.
/// </summary>
void Avake(){
    // this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
    PhotonNetwork.automaticallySyncScene = true;


}

void Start(){
    // the following line checks if this client was just created (and not yet online). if so, we connect
    if (PhotonNetwork.connectionStateDetailed == ClientState.PeerCreated)
    {
        Debug.Log ("connecting");
        // Connect to the photon master-server. We use the settings saved in PhotonServerSettings (a .asset file in this project)
        PhotonNetwork.ConnectUsingSettings("0.9");
    }
}

public void OnJoinedLobby()
{
    Debug.Log("DemoAnimator/Launcher: OnJoinedLobby() was called by PUN");
    PhotonNetwork.JoinRandomRoom();
}
public override void OnConnectedToMaster()
{
    Debug.Log("DemoAnimator/Launcher: OnConnectedToMaster() was called by PUN");
    PhotonNetwork.JoinRandomRoom();
}

public override void OnDisconnectedFromPhoton()
{

    Debug.LogWarning("DemoAnimator/Launcher: OnDisconnectedFromPhoton() was called by PUN");        
}

public override void OnPhotonRandomJoinFailed(object[] codeAndMsg){
    Debug.LogWarning("DemoAnimator/Launcher: Failing joining random room");
    PhotonNetwork.CreateRoom (null, new RoomOptions (){ MaxPlayers = 4 }, null);
}
public override void OnJoinedRoom(){
    Debug.LogWarning("DemoAnimator/Launcher: Joined room");
}


public void OnFailedToConnectToPhoton(object parameters)
{
    Debug.Log("OnFailedToConnectToPhoton. StatusCode: " + parameters + " ServerAddress: " + PhotonNetwork.ServerAddress);
}
}

這里是loggs。

Firstlog

Secondlog

我剛剛復制粘貼了您的解決方案,並成功調用了它。假設您使用的是來自PUN資產的PhotonTutorials和Marco Polo示例,我認為您沒有從項目中引用RandomMatchmakera腳本。 這是你的做法

我希望這會對某人有所幫助。 對我來說,問題出在我所在的地區。 我沒有選擇任何區域,而沒有將其指定為特定區域。 因此找到

PhotonServerSettings

歸檔並將區域更改為特定的內容,例如EU,Kr等

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM