我正在尝试根据 Brackeys 的教程来实现 UNET Matchmaking 系统。
我已经在我的 Unity 帐户中启用了多人游戏服务并启用了该服务。
当我尝试创建匹配并从局域网中的另一台 PC 中找到它时,它运行良好。
当我尝试创建匹配并从局域网外的另一台 PC 上找到它时,我在匹配列表中看不到匹配。
我已经搜索了文档和谷歌,但没有找到任何关于它的信息。
有人有线索吗?
顺便说一下,这是我的 JoinRoom 脚本。
回调函数返回成功,但房间列表返回为空。
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using System;
public class JoinGame : MonoBehaviour
{
List<GameObject> roomList = new List<GameObject>();
[SerializeField] GameObject roomListItemPrefab;
[SerializeField] Transform roomListParent;
[SerializeField] Text status;
private NetworkManager networkManager;
void Start()
{
networkManager = NetworkManager.singleton;
if (networkManager.matchMaker == null)
{
networkManager.StartMatchMaker();
}
RefreshRoomList();
}
public void RefreshRoomList()
{
ClearRoomList();
networkManager.matchMaker.ListMatches(0, 20, "", false, 0, 0, OnMatchList);
status.text = "Loading...";
}
public void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> responseData)
{
status.text = "";
if (!success)
{
status.text = "Couldn't get room list";
return;
}
responseData.ForEach(match =>
{
GameObject _roomListItemGO = Instantiate(roomListItemPrefab);
_roomListItemGO.transform.SetParent(roomListParent);
RoomListItem _roomListItem = _roomListItemGO.GetComponent<RoomListItem>();
if (_roomListItem != null)
{
_roomListItem.Setup(match, JoinRoom);
}
//as well as setting up a callback function that will join the game
roomList.Add(_roomListItemGO);
});
if (roomList.Count == 0)
{
status.text = "No rooms at the moment";
}
}
public void JoinRoom(MatchInfoSnapshot _match)
{
Debug.Log($"Joining {_match.name}");
networkManager.matchMaker.JoinMatch(_match.networkId, "", "", "", 0, 0, networkManager.OnMatchJoined);
ClearRoomList();
status.text = $"Joining {_match.name}...";
}
private void ClearRoomList()
{
roomList.ForEach(item =>
{
Destroy(item);
});
roomList.Clear();
}
}