我对曼联还很陌生,对于我所看到的行为,我找不到任何合乎逻辑的答案.
我写了一个基本的脚本,如下所示:
public class PlayerPosition : NetworkBehaviour
{
private Dictionary<string, int> testDict = new();
[ServerRpc(RequireOwnership = false)]
private void HitServerRpc(string key, int value)
{
RefreshClientRpc(key, value);
}
[ClientRpc]
private void RefreshClientRpc(string key, int value)
{
testDict[key] = value;
foreach (var item in testDict)
{
Debug.Log($"Item in current dict {item}");
}
}
// Other logical code that calls only HitServerRpc().
}
I am using this script on my player Prefab
in a client / host situation.
I have one client and one host (server + client) for the test and the question.
我的问题是:为什么testDict
只有一个键和一个值,而至少有两个不同的键和值是通过两个不同的RPC调用添加的,每个客户端一个?
即使在两个不同的客户端上调用了HitServerRpc()
,日志(log)Item in current dict
也只显示一次:
-
HitServerRpc("user1", 3)
个 -
HitServerRpc("user2", 4)
个
所有客户端的testDict
都应等于:{{"user1", 3}, {"user2", 4}}
PS:最奇怪的是,我try 在静态类中移动testDict
并在内部更新它,而不是在处理RPC调用的类中进行更新,它现在在主机上有正确的值,但在客户机上仍然没有.