繁体   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