private void OnInstantiate(Socket socket, byte[] data) { C2S_Instantiate clientCmd = NetworkSerializer.Deserialize <C2S_Instantiate>(data); //新增对象数据 instances[clientCmd.TypeId].Add(instanceId, new Entity(clients[socket], clientCmd.X, clientCmd.Y)); S2C_Instantiate cmd = new S2C_Instantiate(); cmd.Frame = clientCmd.Frame; cmd.Instance.TypeId = clientCmd.TypeId; cmd.Instance.Id = instanceId; cmd.Instance.X = clientCmd.X; cmd.Instance.Y = clientCmd.Y; //自增 instanceId++; //广播所有人 foreach (var client in clients.Keys) { if (client == socket) //调用者拥有IsLocal属性 { cmd.Instance.IsLocal = true; } else { cmd.Instance.IsLocal = false; } Send(client, (ushort)NetworkRole.Server, (ushort)GameCmd.Instantiate, cmd); } }
private void OnInstantiated(byte[] data) { S2C_Instantiate cmd = NetworkSerializer.Deserialize <S2C_Instantiate>(data); CreatInstance(cmd.Instance); }