因此,我一直在尝试使用 Photon Bolt 制作游戏,以在 PC 和 Android 设备之间建立连接。当在同一台计算机上连接两个游戏时,它工作正常,但如果我尝试连接两个不同的设备,无论是 PC 到 Android 连接还是 PC 到 PC,我开始遇到问题。在最好的情况下,连接需要很长时间(超时为 100000,连接超时为 5000,连接尝试 20 次),但大多数情况下它甚至没有连接。当客户端尝试连接时,消息 [NAT Ping] Ping [EndPoint IPv4 (my IP)] 开始出现在服务器日志上,但有时它会卡在 Attached [Entity [NetworkId 0-0-0-1-FF- FF-FF-FF] Photon.Bolt.PlatformState] (Token: NULL) 在客户端(PlatformState 是客户端在加载场景后实例化的 Prefab 的状态,
这是启动服务器和客户端的代码(类似于入门教程之一):
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Bolt;
using Photon.Bolt.Matchmaking;
using UdpKit;
//using Udpkit;
public class MenuScript : Photon.Bolt.GlobalEventListener
{
void OnGUI(){
GUILayout.BeginArea(new Rect(10, 10, Screen.width - 20, Screen.height - 20));
if(GUILayout.Button("Start Server", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
{
BoltLauncher.StartServer();
}
if(GUILayout.Button("Start Client", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
{
//JoinSession();
BoltLauncher.StartClient();
}
GUILayout.EndArea();
}
public override void BoltStartDone(){
CreateServerSession();
}
public override void SessionListUpdated(Map<Guid, UdpSession> sessionList)
{
Debug.LogFormat("Session list updated: {0} total sessions", sessionList.Count);
foreach (var session in sessionList)
{
UdpSession photonSession = session.Value as UdpSession;
if (photonSession.Source == UdpSessionSource.Photon)
{
BoltMatchmaking.JoinSession(photonSession);
}
}
}
public void CreateServerSession(){
string matchName = "AB";
BoltMatchmaking.CreateSession(
sessionID:matchName,
sceneToLoad: "Level1"
);
}
public void JoinSession(){
if(BoltNetwork.IsRunning)
{
string id = "AB";
BoltMatchmaking.JoinSession(
sessionID: id
);
}
}
}
希望这是所需的一切,我使用了两个 BoltGlobalBehavior 脚本,但我认为它们对那个问题并不重要(它们在服务器中实例化播放器,在客户端实例化平台)