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; } }
public override void Deserialize(NetworkReader reader) { this.bits = 0; { 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_ResponseSyncVar: while (true) { byte b = reader.ReadByte(); if (b == 0) { break; } uint bits = (uint)(1 << (b - 1)); this.bits |= bits; var state = netObj.GetStateByBits(bits); object value = null; value = Read(reader, state.syncVarInfo.field.FieldType); try { state.value = value; if (netObj != null) { if (state.syncVarInfo.changeCallback != null) { state.syncVarInfo.changeCallback.Invoke(netObj, new object[] { value }); } else { state.syncVarInfo.field.SetValue(netObj, value); } } } catch (Exception ex) { Console.WriteLine(ex); } } break; case Action_RequestSyncVar: bits = reader.ReadUInt32(); break; } } }