【发布时间】:2015-09-15 19:31:57
【问题描述】:
所以我正在统一制作多人游戏。 我已经建立了一些字典来保存分数。 主客户端处理字典。
在主客户端对字典进行更改(例如,因为玩家死亡)并计算出谁处于领先地位之后。我想将数据发送给客户,以便他们可以在那里更新记分牌、hud 等。
但是我似乎无法直接通过 rpc 进行字典。例如这里
[RPC]
void PassScoresToClients (Dictionary plyScrs, Dictionary teamScrs,int leadingTeamID, int leadingTeamScore){
}
字典这个词刚刚变成红色。
有没有办法可以将这些数据发送给客户?
为了论证,我将给出一个简短的例子。 第一个字典保存玩家的杀戮、死亡、助攻和团队ID,使用那里的用户名作为字典键。和得分类型(Kills、Deaths、Assists 和 teamID)作为辅助键。 它的结构是这样的:
Dictionary<string, Dictionary<string, int> > playerScores;
子词典在需要时创建/填充
public void SetScore (string username, string scoreType, int value)
{
Init ();
changeCounter ++;
if (playerScores.ContainsKey (username) == false) {//if the player has not been recorded in the dictionery yet.
playerScores [username] = new Dictionary<string, int> ();// Creates a new dictinerey(sub dictionery) for that player.
}
playerScores [username] [scoreType] = value; // the players score is now the value of value
}
第 2 词典是一个简单的词典,只记录球队得分。 它使用 teamID 作为键 它的结构是这样的:
Dictionary<int, int> teamScores;
字典由主客户端填充,因此客户端只有互补的空字典,直到他们可以接收数据。
那么有没有办法将数据发送给客户端?
哦,如果您有邮政编码,请输入 cmets。我在很多事情上还是很菜鸟,很容易迷路。
【问题讨论】:
标签: c# dictionary unity3d rpc