GKTurnBasedMatch 不会一直前进到下一个玩家(Xamarin、Apple GameKit)
GKTurnBasedMatch doesn't consistently advance to the next player (Xamarin, Apple GameKit)
我正在为棋盘游戏使用回合制比赛,当一个回合完成时,我调用 GKTurnBasedMatch.EndTurn 并将比赛参与者和新的比赛数据作为参数传递。我需要游戏推进到未匹配的玩家,但它只会在与超时值相关的不确定时间后才这样做。将超时值设置为 0 只会阻止游戏继续进行到玩家 1 之后。比赛数据正在更新,因此应用肯定正在与 Game Center 服务器通信。我在这里错过了什么?
private void endTurn(double timeout)
{
// Copies list of participants to a mutable array
GKTurnBasedParticipant[] Participants = new GKTurnBasedParticipant[match.Participants.Length];
match.Participants.CopyTo(Participants, 0);
// Advances to the next player
match.EndTurn(Participants, timeout, matchData, (e) =>
{
// If there is an error message, print it to the console
if (e != null)
{
Console.WriteLine(e.LocalizedDescription);
Console.WriteLine(e.LocalizedFailureReason);
}
// Otherwise proceed normally
else
turnOverUpdate();
});
}
Apple 的 EndTurn 方法文档很差,但我想通了。 NextParticipants 字段应像 EndTurnWithNextParticipant 一样对待,因此您必须复制 GKTurnBasedMatch.Participants 并对其重新排序,以便下一位玩家排在第一位,因此排在第四位。比赛只为您提供参加者的加入顺序,而不是相对于本地玩家的顺序,因此您必须对其进行排序。下面是我用来完成此操作的代码。
List<GKTurnBasedParticipant> participants = new List<GKTurnBasedParticipant>();
// Gets the index of the local player
int index = 0;
for (int i = 0; i < match.Participants.Length; i++)
{
if (match.Participants[i].Player != null)
{
if (match.Participants[i].Player.PlayerID == GKLocalPlayer.LocalPlayer.PlayerID)
{
index = i;
break;
}
}
}
int offset = match.Participants.Length - index;
for (int i = 1; i < offset; i++)
participants.Add(match.Participants[i + index]);
for (int i = 0; i <= index; i++)
participants.Add(match.Participants[i]);
GKTurnBasedParticipant[] nextParticipants = participants.ToArray();
我正在为棋盘游戏使用回合制比赛,当一个回合完成时,我调用 GKTurnBasedMatch.EndTurn 并将比赛参与者和新的比赛数据作为参数传递。我需要游戏推进到未匹配的玩家,但它只会在与超时值相关的不确定时间后才这样做。将超时值设置为 0 只会阻止游戏继续进行到玩家 1 之后。比赛数据正在更新,因此应用肯定正在与 Game Center 服务器通信。我在这里错过了什么?
private void endTurn(double timeout)
{
// Copies list of participants to a mutable array
GKTurnBasedParticipant[] Participants = new GKTurnBasedParticipant[match.Participants.Length];
match.Participants.CopyTo(Participants, 0);
// Advances to the next player
match.EndTurn(Participants, timeout, matchData, (e) =>
{
// If there is an error message, print it to the console
if (e != null)
{
Console.WriteLine(e.LocalizedDescription);
Console.WriteLine(e.LocalizedFailureReason);
}
// Otherwise proceed normally
else
turnOverUpdate();
});
}
Apple 的 EndTurn 方法文档很差,但我想通了。 NextParticipants 字段应像 EndTurnWithNextParticipant 一样对待,因此您必须复制 GKTurnBasedMatch.Participants 并对其重新排序,以便下一位玩家排在第一位,因此排在第四位。比赛只为您提供参加者的加入顺序,而不是相对于本地玩家的顺序,因此您必须对其进行排序。下面是我用来完成此操作的代码。
List<GKTurnBasedParticipant> participants = new List<GKTurnBasedParticipant>();
// Gets the index of the local player
int index = 0;
for (int i = 0; i < match.Participants.Length; i++)
{
if (match.Participants[i].Player != null)
{
if (match.Participants[i].Player.PlayerID == GKLocalPlayer.LocalPlayer.PlayerID)
{
index = i;
break;
}
}
}
int offset = match.Participants.Length - index;
for (int i = 1; i < offset; i++)
participants.Add(match.Participants[i + index]);
for (int i = 0; i <= index; i++)
participants.Add(match.Participants[i]);
GKTurnBasedParticipant[] nextParticipants = participants.ToArray();