public void Instantiate()
 {
     if (Main == null)
     {
         Main    = ModelManagerUI.CreateNew(data.type);
         Context = Main.transform as RectTransform;
     }
     if (parent != null)
     {
         if (Context.parent != parent.Context)
         {
             Context.SetParent(parent.Context);
         }
     }
     LoadToObject(Main.transform);
 }
        unsafe public override void Load(FakeStruct fake)
        {
            data = *(ElementData *)fake.ip;
            var buff = fake.buffer;

            Int16[] coms = buff.GetData(data.coms) as Int16[];
            if (coms != null)
            {
                for (int i = 0; i < coms.Length; i++)
                {
                    int index = coms[i];
                    i++;
                    int type = coms[i];
                    var fs   = buff.GetData(index) as FakeStruct;
                    if (fs != null)
                    {
                        var dc = ModelManagerUI.Load(type);
                        if (dc != null)
                        {
                            dc.Load(fs);
                            components.Add(dc);
                        }
                    }
                }
            }
            Int16[] chi = fake.buffer.GetData(data.child) as Int16[];
            if (chi != null)
            {
                for (int i = 0; i < chi.Length; i++)
                {
                    var fs = buff.GetData(chi[i]) as FakeStruct;
                    if (fs != null)
                    {
                        ModelElement model = new ModelElement();
                        model.Load(fs);
                        model.SetParent(this);
                        //child.Add(model);
                        //model.parent = this;
                    }
                }
            }
            name    = buff.GetData(data.name) as string;
            tag     = buff.GetData(data.tag) as string;
            ModData = fake;
        }
        public static unsafe FakeStruct LoadFromObject(Component com, DataBuffer buffer)
        {
            var trans = com as RectTransform;

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

            ed->localRotation      = trans.localRotation;
            ed->localPosition      = trans.localPosition;
            ed->localScale         = trans.localScale;
            ed->anchoredPosition   = trans.anchoredPosition;
            ed->anchoredPosition3D = trans.anchoredPosition3D;
            ed->anchorMax          = trans.anchorMax;
            ed->anchorMin          = trans.anchorMin;
            ed->offsetMax          = trans.offsetMax;
            ed->offsetMin          = trans.offsetMin;
            ed->pivot     = trans.pivot;
            ed->sizeDelta = trans.sizeDelta;
            ed->name      = buffer.AddData(trans.name);
            ed->tag       = buffer.AddData(trans.tag);
            var coms = com.GetComponents <Component>();

            ed->type = ModelManagerUI.GetTypeIndex(coms);
            List <Int16> tmp = new List <short>();

            for (int i = 0; i < coms.Length; i++)
            {
                var rect = coms[i] as RectTransform;
                if (rect == null)
                {
                    var ss = coms[i] as SizeScaling;
                    if (ss != null)
                    {
                        ed->SizeScale  = true;
                        ed->scaleType  = ss.scaleType;
                        ed->sizeType   = ss.sizeType;
                        ed->anchorType = ss.anchorType;
                        ed->parentType = ss.parentType;
                        ed->margin     = ss.margin;
                        ed->DesignSize = ss.DesignSize;
                    }
                    else if (coms[i] is UICompositeHelp)
                    {
                        ed->ex = buffer.AddData((coms[i] as UICompositeHelp).ToFakeStruct(buffer));
                    }
                    else if (!(coms[i] is CanvasRenderer))
                    {
                        Int16 type = 0;
                        var   fs   = ModelManagerUI.LoadFromObject(coms[i], buffer, ref type);
                        if (type > 0)
                        {
                            tmp.Add((Int16)buffer.AddData(fs));
                            tmp.Add(type);
                        }
                    }
                }
            }
            if (tmp.Count > 0)
            {
                ed->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);
                }
                ed->child = buffer.AddData(buf);
            }
            return(fake);
        }
 public void Recycle()
 {
     ModelManagerUI.RecycleElement(this);
 }