我正在尝试使用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。