Пример #1
0
        private void DestroyCallback(byte[] data)
        {
            S2C_Destroy cmd = NetworkSerializer.Deserialize <S2C_Destroy>(data);
            //获取场景实例
            GameObject instance = instances[cmd.TypeId][cmd.Id];

            //从列表中删除
            instances[cmd.TypeId].Remove(cmd.Id);
            //从场景中删除
            global::Destroy.Object.Destroy(instance);
            //从他人物体中移除
            otherInstances.Remove(cmd.Id);
        }
Пример #2
0
        private void OnDestroy(Socket socket, byte[] data)
        {
            C2S_Destroy clientCmd = NetworkSerializer.Deserialize <C2S_Destroy>(data);

            //移除对象数据
            instances[clientCmd.TypeId].Remove(clientCmd.Id);

            S2C_Destroy cmd = new S2C_Destroy();

            cmd.Frame  = clientCmd.Frame;
            cmd.TypeId = clientCmd.TypeId;
            cmd.Id     = clientCmd.Id;
            //广播除了发送者之外的人
            foreach (var client in clients.Keys)
            {
                if (client == socket)
                {
                    continue;
                }
                Send(client, (ushort)NetworkRole.Server, (ushort)GameCmd.Destroy, cmd);
            }
        }