Exemplo n.º 1
0
    public void get_mission_data(ref byte[] data, ref byte[] url)
    {
        m_map_data.map_ver = m_self_map_ver;
        MemoryStream ms;

        byte[] b = new byte[4];
        for (int m = 0; m < 3; ++m)
        {
            ms = new MemoryStream();
            for (int j = 0; j < m_map_data.maps[m].y_num; ++j)
            {
                for (int i = 0; i < m_map_data.maps[m].x_num; ++i)
                {
                    b = System.BitConverter.GetBytes(m_arrays[m][j][i].type);
                    ms.Write(b, 0, b.Length);
                    for (int k = 0; k < m_arrays[m][j][i].param.Count; ++k)
                    {
                        b = System.BitConverter.GetBytes(m_arrays[m][j][i].param[k]);
                        ms.Write(b, 0, b.Length);
                    }
                }
            }
            m_map_data.maps[m].array = ms.ToArray();
        }

        ms = new MemoryStream();
        ProtoBuf.Serializer.Serialize(ms, m_map_data);
        data = utils.Compress(ms.ToArray());

        protocol.map.map_url murl = new protocol.map.map_url();
        murl.map_theme = m_map_data.maps[0].map_theme;
        int cs = m_map_data.maps[0].qd_y - 2;
        int zs = m_map_data.maps[0].qd_y + 8;

        if (zs > m_map_data.maps[0].y_num)
        {
            zs = m_map_data.maps[0].y_num;
            cs = zs - 10;
        }

        ms = new MemoryStream();
        for (int j = cs; j < zs; ++j)
        {
            for (int i = 0; i < 15; ++i)
            {
                b = System.BitConverter.GetBytes(m_arrays[0][j][i].type);
                ms.Write(b, 0, b.Length);
            }
        }
        murl.array = ms.ToArray();

        ms = new MemoryStream();
        ProtoBuf.Serializer.Serialize(ms, murl);
        url = utils.Compress(ms.ToArray());
    }
Exemplo n.º 2
0
    public Texture2D mission_to_texture(byte[] data)
    {
        if (data.Length == 0)
        {
            return(Resources.Load("texture/back/back") as Texture2D);
        }
        try
        {
            byte[] arr = utils.Decompress(data);
            protocol.map.map_url mu      = net_http._instance.parse_packet <protocol.map.map_url> (arr);
            Texture2D            texture = new Texture2D(360, 240, TextureFormat.RGBA32, false);
            Texture2D            bt      = Resources.Load("texture/back/back_" + mu.map_theme.ToString()) as Texture2D;
            texture.SetPixels(0, 0, 360, 240, bt.GetPixels());

            MemoryStream ms = new MemoryStream(mu.array);
            byte[]       b  = new byte[4];
            for (int j = 0; j < 10; ++j)
            {
                for (int i = 0; i < 15; ++i)
                {
                    ms.Read(b, 0, b.Length);
                    int type = System.BitConverter.ToInt32(b, 0);
                    if (type > 0)
                    {
                        s_t_unit unit = game_data._instance.get_t_unit(type);
                        if (unit == null)
                        {
                            continue;
                        }
                        if (mario._instance.m_self.m_review == 1 && unit.review == 1)
                        {
                            continue;
                        }
                        Texture2D tt = null;
                        if (unit.kfg == 1)
                        {
                            tt = Resources.Load("texture/" + unit.icon + "_" + mu.map_theme.ToString()) as Texture2D;
                        }
                        else
                        {
                            tt = Resources.Load("texture/" + unit.icon) as Texture2D;
                        }
                        Color[] c = tt.GetPixels();
                        for (int y = 0; y < 24; ++y)
                        {
                            for (int x = 0; x < 24; ++x)
                            {
                                Color cc  = c[y * 24 + x];
                                Color cc1 = texture.GetPixel(i * 24 + x, j * 24 + y);
                                cc.r = cc.r * cc.a + cc1.r * (1 - cc.a);
                                cc.g = cc.g * cc.a + cc1.g * (1 - cc.a);
                                cc.b = cc.b * cc.a + cc1.b * (1 - cc.a);
                                cc.a = 1;
                                texture.SetPixel(i * 24 + x, j * 24 + y, cc);
                            }
                        }
                    }
                }
            }
            texture.Apply(false);

            return(texture);
        }
        catch (System.Exception)
        {
            return(Resources.Load("texture/back/back") as Texture2D);
        }
    }