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);
        }
Example #2
0
        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->instanceID = trans.GetInstanceID();
            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->anchorType      = ss.anchorType;
                        ed->anchorpointType = ss.anchorPointType;
                        ed->anchorOffset    = ss.anchorOffset;
                        ed->marginType      = ss.marginType;
                        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).ToBufferData(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 UNITY_EDITOR
                        else if (com.name != "Canvas")
                        {
                            var t = com.transform;
                            System.Text.StringBuilder sb = new System.Text.StringBuilder();
                            for (int j = 0; j < 32; j++)
                            {
                                if (t.parent == null)
                                {
                                    sb.Insert(0, t.name);
                                    break;
                                }
                                else
                                {
                                    sb.Insert(0, "/" + t.name);
                                }
                                t = t.parent;
                            }
                            Debug.Log(sb.ToString());
                        }
#endif
                    }
                }
            }
            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);
        }