예제 #1
0
        int WriteStructList(object value, DataBuffer db, DataTypeInfo info)
        {
            var list = value as IList;

            if (list != null)
            {
                if (list.Count > 0)
                {
                    int    el  = info.ElementLength;
                    int    dl  = info.DataLength;
                    IntPtr ptr = UnsafeOperation.GetObjectAddr(list);
                    ptr = UnsafeOperation.GetListElement(ptr, 0);

                    FakeStructArray fsa = new FakeStructArray(db, el, list.Count);
                    unsafe
                    {
                        FakeStruct fs = new FakeStruct(db, el, fsa.ip);
                        for (int i = 0; i < list.Count; i++)
                        {
                            fs.SetPoint(fsa[i]);
                            WriteStruct(info, ptr, fs);
                            ptr += dl;
                        }
                    }
                    return(db.AddData(fsa, DataType.FakeStructArray));
                }
            }
            return(0);
        }
예제 #2
0
        FakeStructArray SaveCategory(DataBuffer buffer)
        {
            FakeStructArray array = new FakeStructArray(buffer, 2, lsc.Count);

            for (int i = 0; i < lsc.Count; i++)
            {
                array.SetData(i, 0, lsc[i].txtName);
                array.SetData(i, 1, SaveSprites(buffer, lsc[i].sprites));
            }
            return(array);
        }
예제 #3
0
        unsafe FakeStructArray SaveSprites(DataBuffer buffer, List <Sprite> sprites)
        {
            FakeStructArray array = new FakeStructArray(buffer, SpriteDataS.ElementSize, sprites.Count);
            float           tx    = sprites[0].texture.width;
            float           ty    = sprites[0].texture.height;

            for (int i = 0; i < sprites.Count; i++)
            {
                var          sprite = sprites[i];
                string       name   = sprite.name;
                SpriteDataS *sp     = (SpriteDataS *)array[i];
                sp->name      = buffer.AddData(name);
                sp->txtSize.x = tx;
                sp->txtSize.y = ty;
                sp->rect      = sprite.rect;
                sp->pivot     = sprite.pivot;
            }
            return(array);
        }
예제 #4
0
        SpriteInfo[] LoadSpriteData(FakeStructArray array)
        {
            var db = array.buffer;

            SpriteInfo[] spr = new SpriteInfo[array.Length];
            for (int i = 0; i < spr.Length; i++)
            {
                unsafe
                {
                    SpriteDataS *sp = (SpriteDataS *)array[i];
                    spr[i].rect  = sp->rect;
                    spr[i].pivot = sp->pivot;
                    spr[i].Name  = db.GetData(sp->name) as string;
                    spr[i].uv    = new Vector2[4];
                    spr[i].uv[0] = sp->uv0;
                    spr[i].uv[1] = sp->uv1;
                    spr[i].uv[2] = sp->uv2;
                    spr[i].uv[3] = sp->uv3;
                }
            }
            return(spr);
        }
예제 #5
0
        unsafe FakeStructArray SaveSprites(DataBuffer buffer, List <Sprite> sprites)
        {
            FakeStructArray array = new FakeStructArray(buffer, SpriteDataS.ElementSize, sprites.Count);
            float           tx    = sprites[0].texture.width;
            float           ty    = sprites[0].texture.height;

            for (int i = 0; i < sprites.Count; i++)
            {
                var          sprite = sprites[i];
                string       name   = sprite.name;
                SpriteDataS *sp     = (SpriteDataS *)array[i];
                sp->name      = buffer.AddData(name);
                sp->txtSize.x = tx;
                sp->txtSize.y = ty;
                var sr = sp->rect = sprite.rect;
                sp->pivot = sprite.pivot;
                float w  = sprite.texture.width;
                float h  = sprite.texture.width;
                float x  = sr.x;
                float rx = sr.width + x;
                float y  = sr.y;
                ty        = sr.height + y;
                x        /= w;
                rx       /= w;
                y        /= h;
                ty       /= h;
                sp->uv0.x = x;
                sp->uv0.y = y;
                sp->uv1.x = x;
                sp->uv1.y = ty;
                sp->uv2.x = rx;
                sp->uv2.y = ty;
                sp->uv3.x = rx;
                sp->uv3.y = y;
            }
            return(array);
        }
예제 #6
0
        int WriteStructArray(object value, DataBuffer db, DataTypeInfo info)
        {
            var list = value as IList;

            if (list != null)
            {
                if (list.Count > 0)
                {
                    int             el  = info.ElementLength;
                    FakeStructArray fsa = new FakeStructArray(db, el, list.Count);
                    unsafe
                    {
                        FakeStruct fs = new FakeStruct(db, el, fsa.ip);
                        for (int i = 0; i < list.Count; i++)
                        {
                            fs.SetPoint(fsa[i]);
                            WriteStruct(info, list[i], fs);
                        }
                    }
                    return(db.AddData(fsa, DataType.FakeStructArray));
                }
            }
            return(0);
        }
예제 #7
0
 object ReadObjectList(DataFieldInfo info, DataBuffer buffer, Object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var   con  = info.Construction();
             IList list = con as IList;
             for (int i = 0; i < addr16.Length; i++)
             {
                 var fs = buffer.GetData(addr16[i]) as FakeStruct;
                 if (fs != null)
                 {
                     list.Add(ReadObject(info.typeInfo, fs, addr16[i]));
                 }
                 else
                 {
                     list.Add(null);
                 }
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.Construction();
                 IList list     = con as IList;
                 for (int i = 0; i < addr32.Length; i++)
                 {
                     int a     = addr32[i];
                     int index = a & 0xffff;
                     var fs    = buffer.GetData(index) as FakeStruct;
                     if (fs != null)
                     {
                         if (isStruct)//结构体无法使用继承
                         {
                             list.Add(ReadObject(info.typeInfo, fs, index));
                         }
                         else
                         {
                             var dt = oldTypes[a >> 16].NewType; //使用继承类型
                             if (dt == null)                     //没有找到继承类型则使用默认类型
                             {
                                 list.Add(null);
                             }
                             else
                             {
                                 list.Add(ReadObject(dt, fs, index));
                             }
                         }
                     }
                     else
                     {
                         list.Add(null);
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.Construction();
                     IList list = con as IList;
                     for (int i = 0; i < fsa.Length; i++)
                     {
                         unsafe { fs.SetPoint(fsa[i]); }
                         list.Add(ReadStruct(info.typeInfo, fs, 0));
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
예제 #8
0
 object ReadObjectArray(DataFieldInfo info, DataBuffer buffer, Object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var   con  = info.ArrayConstruction(addr16.Length);
             Array arry = con as Array;
             if (arry != null)
             {
                 for (int i = 0; i < addr16.Length; i++)
                 {
                     var fs = buffer.GetData(addr16[i]) as FakeStruct;
                     if (fs != null)
                     {
                         arry.SetValue(ReadObject(info.typeInfo, fs, addr16[i]), i);
                     }
                 }
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.ArrayConstruction(addr32.Length);
                 Array arry     = con as Array;
                 if (arry == null)
                 {
                     for (int i = 0; i < addr32.Length; i++)
                     {
                         int a     = addr32[i];
                         int index = a & 0xffff;
                         var fs    = buffer.GetData(index) as FakeStruct;
                         if (fs != null)
                         {
                             if (isStruct)//结构体无法使用继承
                             {
                                 arry.SetValue(ReadObject(info.typeInfo, fs, index), i);
                             }
                             else
                             {
                                 var dt = oldTypes[a >> 16].NewType;//使用继承类型
                                 if (dt == null)
                                 {
                                     dt = info.typeInfo;
                                 }
                                 arry.SetValue(ReadObject(dt, fs, index), i);
                             }
                         }
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.ArrayConstruction(fsa.Length);
                     Array arry = con as Array;
                     if (arry != null)
                     {
                         for (int i = 0; i < fsa.Length; i++)
                         {
                             unsafe { fs.SetPoint(fsa[i]); }
                             arry.SetValue(ReadStruct(info.typeInfo, fs, 0), i);
                         }
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
예제 #9
0
 object ReadStructList(DataFieldInfo info, DataBuffer buffer, object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             var    con  = info.Construction();
             IList  list = con as IList;
             var    tmp  = info.typeInfo.Construction();
             IntPtr ptr  = UnsafeOperation.GetStructAddr(tmp);
             for (int i = 0; i < addr16.Length; i++)
             {
                 unsafe
                 {
                     byte *bp = (byte *)ptr;
                     for (int j = 0; j < info.typeInfo.DataLength; j++)
                     {
                         bp[j] = 0;
                     }
                 }
                 var fs = buffer.GetData(addr16[i]) as FakeStruct;
                 if (fs != null)
                 {
                     ReadStruct(info.typeInfo, fs, 0, ptr);
                 }
                 list.Add(tmp);
             }
             return(con);
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool   isStruct = info.typeInfo.isStruct;
                 var    con      = info.Construction();
                 IList  list     = con as IList;
                 var    tmp      = info.typeInfo.Construction();
                 IntPtr ptr      = UnsafeOperation.GetStructAddr(tmp);
                 for (int i = 0; i < addr32.Length; i++)
                 {
                     unsafe
                     {
                         byte *bp = (byte *)ptr;
                         for (int j = 0; j < info.typeInfo.DataLength; j++)
                         {
                             bp[j] = 0;
                         }
                     }
                     int a     = addr32[i];
                     int index = a & 0xffff;
                     var fs    = buffer.GetData(index) as FakeStruct;
                     if (fs != null)
                     {
                         ReadStruct(info.typeInfo, fs, 0, ptr);
                     }
                     list.Add(tmp);
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var    con  = info.Construction();
                     IList  list = con as IList;
                     var    tmp  = info.typeInfo.Construction();
                     IntPtr ptr  = UnsafeOperation.GetStructAddr(tmp);
                     for (int i = 0; i < fsa.Length; i++)
                     {
                         unsafe
                         {
                             byte *bp = (byte *)ptr;
                             for (int j = 0; j < info.typeInfo.DataLength; j++)
                             {
                                 bp[j] = 0;
                             }
                         }
                         unsafe { fs.SetPoint(fsa[i]); }
                         ReadStruct(info.typeInfo, fs, 0, ptr);
                         list.Add(tmp);
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
예제 #10
0
 object ReadStructArray(DataFieldInfo info, DataBuffer buffer, object obj)
 {
     if (obj != null)
     {
         Int16[] addr16 = obj as Int16[];
         if (addr16 != null)
         {
             if (addr16.Length > 0)
             {
                 var   con  = info.ArrayConstruction(addr16.Length);
                 Array arry = con as Array;
                 if (arry != null)
                 {
                     IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                     for (int i = 0; i < addr16.Length; i++)
                     {
                         var fs = buffer.GetData(addr16[i]) as FakeStruct;
                         if (fs != null)
                         {
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                         }
                         ptr += info.DataLength;
                     }
                 }
                 return(con);
             }
         }
         else
         {
             Int32[] addr32 = obj as Int32[];
             if (addr32 != null)
             {
                 bool  isStruct = info.typeInfo.isStruct;
                 var   con      = info.ArrayConstruction(addr32.Length);
                 Array arry     = con as Array;
                 if (arry == null)
                 {
                     IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                     for (int i = 0; i < addr32.Length; i++)
                     {
                         int a     = addr32[i];
                         int index = a & 0xffff;
                         var fs    = buffer.GetData(index) as FakeStruct;
                         if (fs != null)
                         {
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                         }
                         ptr += info.DataLength;
                     }
                 }
                 return(con);
             }
             else
             {
                 FakeStructArray fsa = obj as FakeStructArray;
                 if (fsa != null)
                 {
                     FakeStruct fs;
                     unsafe
                     {
                         fs = new FakeStruct(buffer, fsa.StructSize, fsa.ip);
                     }
                     var   con  = info.ArrayConstruction(fsa.Length);
                     Array arry = con as Array;
                     if (arry != null)
                     {
                         IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(arry, 0);
                         for (int i = 0; i < fsa.Length; i++)
                         {
                             unsafe { fs.SetPoint(fsa[i]); }
                             ReadStruct(info.typeInfo, fs, 0, ptr);
                             ptr += info.DataLength;
                         }
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }