Ejemplo n.º 1
0
 /// <summary>
 /// 将游戏对象数据写入假结构体
 /// </summary>
 /// <param name="com">unity组件</param>
 /// <param name="buffer">DataBuffer</param>
 /// <returns></returns>
 public virtual FakeStruct LoadFromObject(Component com, DataBuffer buffer)
 {
     return(null);
 }
Ejemplo n.º 2
0
        public unsafe override FakeStruct LoadFromObject(Component com, DataBuffer buffer)
        {
            var trans = com as Transform;

            if (trans == null)
            {
                return(null);
            }
            FakeStruct     fake = new FakeStruct(buffer, TransfromData.ElementSize);
            TransfromData *td   = (TransfromData *)fake.ip;

            td->localEulerAngles = trans.localEulerAngles;
            td->localPosition    = trans.localPosition;
            td->localScale       = trans.localScale;
            td->name             = buffer.AddData(trans.name);
            td->tag = buffer.AddData(trans.tag);
            var coms = com.GetComponents <Component>();

            td->type  = gameobjectBuffer.GetTypeID(coms);
            td->layer = trans.gameObject.layer;
            List <Int16> tmp = new List <short>();

            for (int i = 0; i < coms.Length; i++)
            {
                if (coms[i] is UICompositeHelp)
                {
                    td->ex = buffer.AddData((coms[i] as UICompositeHelp).ToBufferData(buffer));
                }
                else
                if (!(coms[i] is Transform))
                {
                    Int32 type   = gameobjectBuffer.GetTypeIndex(coms[i]);
                    var   loader = gameobjectBuffer.GetDataLoader(type);
                    if (loader != null)
                    {
                        var fs = loader.LoadFromObject(coms[i], buffer);
                        tmp.Add((Int16)buffer.AddData(fs));
                    }
                    else
                    {
                        tmp.Add(0);
                    }
                    tmp.Add((Int16)type);
                    var scr = coms[i] as UIElement;
                    if (scr != null)
                    {
                        td->size  = scr.SizeDelta;
                        td->pivot = scr.Pivot;
                    }
                }
            }
            td->coms = buffer.AddData(tmp.ToArray());
            int c = trans.childCount;

            if (c > 0)
            {
                Int16[] buf = new short[c];
                for (int i = 0; i < c; i++)
                {
                    var fs = LoadFromObject(trans.GetChild(i), buffer);
                    buf[i] = (Int16)buffer.AddData(fs);
                }
                td->child = buffer.AddData(buf);
            }
            return(fake);
        }
Ejemplo n.º 3
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(ReadStructToObject(info.typeInfo, fs, 0));
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
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(ReadStructToObject(info.typeInfo, fs, 0), i);
                         }
                     }
                     return(con);
                 }
             }
         }
     }
     return(null);
 }
Ejemplo n.º 6
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);
 }