public override void Serialize(NetworkWriter writer) { if (action == 0) { throw new Exception("action is 0"); } var info = SyncListInfo.GetSyncListInfo(netObj.GetType(), memberIndex); writer.WriteByte(action); writer.WriteNetworkInstanceId(netObj.InstanceId); writer.WriteByte(memberIndex); switch (action) { case Action_Add: case Action_Insert: case Action_Set: object list = info.field.GetValue(netObj); if (action == Action_Insert || action == Action_Set) { writer.WriteByte(itemIndex); } object item = info.ItemProperty.GetGetMethod().Invoke(list, new object[] { (int)itemIndex }); info.SerializeItemMethod.Invoke(list, new object[] { writer, item }); break; case Action_RemoveAt: writer.WriteByte(itemIndex); break; } }
public override void Deserialize(NetworkReader reader) { action = reader.ReadByte(); NetworkInstanceId instanceId; instanceId = reader.ReadNetworkInstanceId(); netObj = null; netObj = conn.GetObject(instanceId); if (netObj == null) { return; } memberIndex = reader.ReadByte(); var info = SyncListInfo.GetSyncListInfo(netObj.GetType(), memberIndex); object list = info.field.GetValue(netObj); switch (action) { case Action_Add: case Action_Insert: case Action_Set: { if (action == Action_Add) { itemIndex = (byte)(int)info.CountProperty.GetGetMethod().Invoke(list, null); } else { itemIndex = reader.ReadByte(); } object item; item = info.DeserializeItemMethod.Invoke(list, new object[] { reader }); info.InsertMethod.Invoke(list, new object[] { (int)itemIndex, item }); } break; case Action_RemoveAt: case Action_Remove: if (action == Action_Remove) { itemIndex = (byte)(int)info.CountProperty.GetGetMethod().Invoke(list, null); } else { itemIndex = reader.ReadByte(); } info.RemoveAtMethod.Invoke(list, new object[] { itemIndex }); break; case Action_Clear: info.ClearMethod.Invoke(list, null); break; } }
public override void Deserialize(NetworkReader reader) { action = reader.ReadByte(); if (action == 0) { throw new Exception("action is 0"); } NetworkInstanceId instanceId; instanceId = reader.ReadNetworkInstanceId(); netObj = null; netObj = conn.GetObject(instanceId); if (netObj == null) { return; } switch (action) { case Action_RpcClient: case Action_RpcServer: if (action == Action_RpcClient) { if (!netObj.IsClient) { return; } } else if (action == Action_RpcServer) { if (!netObj.IsServer) { return; } } byte memberIndex = reader.ReadByte(); rpcInfo = RpcInfo.GetRpcInfo(netObj.GetType(), memberIndex); object[] args = null; if (rpcInfo.paramCount > 0) { args = new object[rpcInfo.paramCount]; for (int i = 0; i < rpcInfo.paramCount; i++) { var pInfo = rpcInfo.parameters[i]; if (i == 0 && pInfo.ParameterType == typeof(NetworkConnection)) { args[i] = conn; } else { args[i] = SyncVarMessage.Read(reader, pInfo.ParameterType); } } } rpcInfo.method.Invoke(netObj, args); break; } }