【发布时间】:2019-02-19 11:48:36
【问题描述】:
我可以创建带有邀请的游戏,我可以邀请和接受邀请,这一切都很好。当我为 3 人或更多人制作游戏时出现此问题:
- 用户 A 创建 3 人或至少 2 人的游戏
- 用户 A 选择邀请某人,然后添加另一个人来自动选择房间
- 用户 A 邀请用户 B
- 用户 B 接受
- 他们都等到“立即开始”按钮出现
- 用户 B 按下立即开始按钮,由于某种原因 OnRoomConnected() 被调用了 3 次,游戏没有开始(据我所知,房间也从未离开过,因为该用户无法接收邀请不再)
- 从用户 A 的角度来看没有任何变化,他仍在等待游戏开始或搜索另一个自动选择对手
我确定问题不在于我的代码。我创建了一个单独的简单项目,仅用于测试目的,它做的事情完全相同。所以我开始认为这可能不是我的问题,我在互联网上没有看到类似的问题。所以我决定在这里问。我该怎么办?可能是什么问题?
基本上就是这样。即使我将玩家数量限制为 3 或 4(最小和最大玩家数量相等,3 或 4),它仍然让我过早地开始游戏,并且我在多次调用 OnRoomConnected() 时遇到同样的问题并且游戏没有开始。
提前致谢。如果您有链接或可以帮助我解决此问题的内容,将不胜感激。
这是我用于登录游戏和创建房间的基本代码。
public class GPGM : MonoBehaviour, RealTimeMultiplayerListener{
public static GPGM instance;
public static int target;
private void Awake()
{
target = 60;
QualitySettings.vSyncCount = 0;
Application.targetFrameRate = target;
if (instance == null)
{
DontDestroyOnLoad(gameObject);
instance = this;
}
else if (instance != this)
{
Destroy(gameObject);
}
}
// Use this for initialization
void Start () {
Login();
}
// Update is called once per frame
void Update () {
}
public void Login()
{
StartCoroutine(checkInternetConnection((isConnected) =>
{
LoginGPG();
}));
}
IEnumerator checkInternetConnection(Action<bool> action)
{
WWW www;
www = new WWW("http://google.com");
yield return www;
if (!String.IsNullOrEmpty(www.error))
{
Debug.Log("DebugM | no internet connection");
action(false);
}
else
{
Debug.Log("DebugM | There IS connection");
action(true);
}
}
public void LoginGPG()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().WithInvitationDelegate(OnInvitationReceived).Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Debug.Log("DebugM | LoginGPG");
Auth();
}
public void Auth()
{
Debug.Log("DebugM | Auth");
try
{
//doesn't work sometimes for some reason. It gives null data if success is false
//reason for false success is unknown
Social.localUser.Authenticate((bool succes) =>
{
if (succes)
{
Debug.Log("DebugM | Logged in");
}else
{
Debug.Log("DebugM | authentication failed");
}
});
}
catch (Exception e)
{
Debug.Log("DebugM | Auth() has failed with error: " + e.Message);
}
}
public void OnInvitationReceived(Invitation invitation, bool shouldAutoAccept)
{
StartCoroutine(InvitationCo(invitation, shouldAutoAccept));
}
Invitation mIncomingInvitation;
IEnumerator InvitationCo(Invitation invitation, bool shouldAutoAccept)
{
yield return new WaitUntil(() => SceneManager.GetActiveScene().name == "Lobby");
Debug.Log("DebugM | Invitation has been received!!!");
//StartCoroutine(LM.LoadingAnim());
if (shouldAutoAccept)
{
Debug.Log("DebugM | Should auto accept: TRUE");
PlayGamesPlatform.Instance.RealTime.AcceptInvitation(invitation.InvitationId, instance);
}
else
{
// The user has not yet indicated that they want to accept this invitation.
// We should *not* automatically accept it. Rather we store it and
// display an in-game popup:
Debug.Log("DebugM | Should auto accept: FALSE");
Lobby LM = FindObjectOfType<Lobby>();
LM.invPanel.SetActive(true);
mIncomingInvitation = invitation;
}
}
public void AcceptGoogleInv(GameObject panel)
{
if (mIncomingInvitation != null)
{
// show the popup
//string who = (mIncomingInvitation.Inviter != null &&
// mIncomingInvitation.Inviter.DisplayName != null) ?
// mIncomingInvitation.Inviter.DisplayName : "Someone";
Debug.Log("DebugM | Invitation has been accepted");
PlayGamesPlatform.Instance.RealTime.AcceptInvitation(mIncomingInvitation.InvitationId, instance);
panel.SetActive(false);
}
}
public void CreateQuickRoom()
{
PlayGamesPlatform.Instance.RealTime.CreateWithInvitationScreen(1, 3, 1, instance );
}
public void OnRoomSetupProgress(float percent)
{
Debug.Log("OnRoomSetupProgress()");
PlayGamesPlatform.Instance.RealTime.ShowWaitingRoomUI();
}
public void OnRoomConnected(bool success)
{
SceneManager.LoadScene("Game");
Debug.Log("DebugM | Room conected");
}
public void OnLeftRoom()
{
throw new NotImplementedException();
}
public void OnParticipantLeft(Participant participant)
{
throw new NotImplementedException();
}
public void OnPeersConnected(string[] participantIds)
{
throw new NotImplementedException();
}
public void OnPeersDisconnected(string[] participantIds)
{
throw new NotImplementedException();
}
public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data)
{
throw new NotImplementedException();
}}
【问题讨论】:
-
找到任何解决方案了吗?我也在研究它,自动匹配工作正常,但是当我尝试调用 CreateWithInvitation 时,它正在加载邀请屏幕,但是没有做任何事情,我按下后退按钮它会自动调用自动匹配,这不应该发生......并且如果我从邀请屏幕中选择一个用户并单击邀请,我将返回主屏幕。
-
很遗憾没有...我也在他们的 github 上发布了这个问题,但没有得到任何回应。 :\
-
你如何显示开始按钮?并单击您要调用的方法?为什么要在 OnRoomConnected 中加载游戏场景?
-
每当我邀请至少 1 个人并且他进入房间并且我们等待自动选择或其他被邀请的玩家时,就会出现开始按钮。单击时,我不知道正在调用哪种方法。我没有看到它的文档。关于场景的加载。因为房间设置好后,就可以安全启动游戏了,所以我通过加载游戏场景来做到这一点。
-
我明白了...你的意思是当你从邀请屏幕中选择一个人时的默认开始按钮对吧?
标签: android unity3d google-play-games