我有一个结构,我在SyncListStruct上用作一个类型,然后我从SyncListStruct继承,允许我有一个列表,其中包含可以从客户端同步到服务器的结构。我得到的问题是SyncListStruct的子类的声明给我以下错误:
InvalidOperationException:不同步 System.Collections.Generic.Dictionary`2 +枚举[System.String,System.Int32] .VerifyState () (在 /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:912) System.Collections.Generic.Dictionary`2 +枚举[System.String,System.Int32] .MoveNext () (在 /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:835) System.Collections.Generic.Dictionary`2 + KeyCollection +枚举[System.String,System.Int32] .MoveNext () (在 /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:1028) UnityEngine.Networking.NetworkCRC.Dump (UnityEngine.Networking.NetworkSystem.CRCMessageEntry [] remoteScripts) (在 C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkCRC.cs:106) UnityEngine.Networking.NetworkCRC.ValidateInternal (UnityEngine.Networking.NetworkSystem.CRCMessageEntry [] remoteScripts, Int32 numChannels)(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkCRC.cs:75) UnityEngine.Networking.NetworkCRC.Validate (UnityEngine.Networking.NetworkSystem.CRCMessageEntry []脚本,Int32 numChannels)(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkCRC.cs:66) UnityEngine.Networking.NetworkClient.OnCRC (UnityEngine.Networking.NetworkMessage netMsg)(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:801) UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader阅读器,Int32 receivedSize, Int32 channelId)(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:430) UnityEngine.Networking.NetworkConnection.HandleBytes(System.Byte [] 缓冲区,Int32 receivedSize,Int32 channelId)(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:386) UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte [] bytes,Int32 numBytes,Int32 channelId)(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:536) UnityEngine.Networking.NetworkClient.Update()(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:648) UnityEngine.Networking.NetworkClient.UpdateClients()(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:861) UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate()(at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1055)
我的代码:
public class TestClass: NetworkBehaviour
{
public struct PlayerShootingStats
{
public string name;
public int totalShots;
public int onTargetShots;
}
public class SyncListPlayerShootingStats : SyncListStruct<PlayerShootingStats>{}
private SyncListPlayerShootingStats playersShootingStats; // if I comment out this line I do not get an error
void Awake()
{
playersShootingStats = new SyncListPlayerShootingStats();
DontDestroyOnLoad(gameObject);
}
}
提前感谢您的帮助。