所以我在統一製作多人遊戲。 我建立了一些Dictionary來保存分數。 主客戶端處理字典的。如何通過rpc發送字典
在主客戶端對字典進行更改(例如因爲玩家死亡)並計算出誰是主角之後。我想將數據發送給客戶,以便他們可以更新記分牌,hud等。
但是,我似乎不能直接通過rpc字典。例如這裏
[RPC]
void PassScoresToClients (Dictionary plyScrs, Dictionary teamScrs,int leadingTeamID, int leadingTeamScore){
}
字典字典變成了紅色。
有沒有辦法將這些數據發送給客戶端?
爲了論證的緣故,我將舉一個簡短的例子。 The First dictionary使用那裏保存玩家的殺人,死亡,助手和teamID用戶名作爲字典鍵。和分數類型(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
}
第二屆字典是一個簡單的,只是跟蹤球隊得分的創建/填充。 它使用的teamID的關鍵 其結構是這樣的:
Dictionary<int, int> teamScores;
字典的由主客戶端被填充,因此客戶端只具有互補空字典在直到他們可以接收數據。
那麼有沒有辦法將數據發送到客戶端?
哦,如果你做郵政編碼,你可以請你留言。我對很多事情仍然很不高興,很容易迷失方向。
你使用UNet嗎? – user3071284