Esempio n. 1
0
 public ModelElement()
 {
     data.localScale    = Vector3.one;
     data.localRotation = Quaternion.identity;
     data.type          = ModelManagerUI.GetTypeIndex(this);
     data.anchorMax     = data.anchorMin = data.pivot = new Vector2(0.5f, 0.5f);
 }
        public T ComponentReflection <T>() where T : class, new()
        {
            T t = new T();

            ModelManagerUI.ComponentReflection(this, t);
            return(t);
        }
        public T AddComponent <T>() where T : DataConversion, new()
        {
            T t = new T();

            data.type |= ModelManagerUI.GetTypeIndex(t);
            components.Add(t);
            return(t);
        }
Esempio n. 4
0
        unsafe public void Clone(FakeStruct fake, List <AssociatedInstance> table)
        {
            data    = *(ElementData *)fake.ip;
            ModData = fake;
            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;
                    var dc   = ModelManagerUI.Load(type);
                    if (dc != null)
                    {
                        dc.model = this;
                        if (fs != null)
                        {
                            dc.Load(fs);
                        }
                        components.Add(dc);
                        if (dc.Entity)
                        {
                            EnityType |= ((long)1 << type);
                        }
                    }
                }
            }
            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.Clone(fs, table);
                        child.Add(model);
                        model.parent = this;
                        AssociatedInstance instance = new AssociatedInstance();
                        instance.id     = model.data.instanceID;
                        instance.target = model;
                        table.Add(instance);
                    }
                }
            }
            name = buff.GetData(data.name) as string;
            tag  = buff.GetData(data.tag) as string;
        }
Esempio n. 5
0
 public void ClearChild(bool recycle = true)
 {
     for (int i = 0; i < child.Count; i++)
     {
         child[i].parent = null;
         if (recycle)
         {
             ModelManagerUI.RecycleElement(child[i]);
         }
     }
     child.Clear();
 }
        public static ModelElement CreateNew(string name)
        {
            var mod = new ModelElement();

            mod.name               = name;
            mod.data.localScale    = Vector3.one;
            mod.data.localRotation = Quaternion.identity;
            mod.data.anchorMax     = mod.data.anchorMin =
                mod.data.pivot     = new Vector2(0.5f, 0.5f);
            mod.data.type         |= ModelManagerUI.GetTypeIndex(mod);
            return(mod);
        }
Esempio n. 7
0
        unsafe public override void Load(FakeStruct fake)
        {
            data    = *(ElementData *)fake.ip;
            ModData = fake;
            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;
                    var dc   = ModelManagerUI.Load(type);
                    if (dc != null)
                    {
                        dc.model = this;
                        if (fs != null)
                        {
                            dc.Load(fs);
                        }
                        components.Add(dc);
                        if (dc.Entity)
                        {
                            EnityType |= ((long)1 << type);
                        }
                    }
                }
            }
            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);
                        child.Add(model);
                        model.parent = this;
                    }
                }
            }
            name = buff.GetData(data.name) as string;
            tag  = buff.GetData(data.tag) as string;
        }
Esempio n. 8
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);
        }
 public override void Apply()
 {
     if (activeSelf)
     {
         if (Context == null)
         {
             var obj = ModelManagerUI.CreateNew(data.type);
             if (obj != null)
             {
                 LoadToObject(obj.transform);
             }
         }
         else
         {
             if (parentChanged)
             {
                 if (parent != null)
                 {
                     Context.SetParent(parent.Context);
                     Context.SetSiblingIndex(parent.child.IndexOf(this));
                 }
                 else
                 {
                     Context.SetParent(null);
                 }
             }
             if (IsChanged)
             {
                 IsChanged = false;
                 LoadToObject(Context, ref data, this);
             }
         }
         if (mIndex > -1)
         {
             if (mIndex > Context.childCount)
             {
                 Context.SetAsLastSibling();
             }
             else
             {
                 Context.SetSiblingIndex(mIndex);
             }
             mIndex = -1;
         }
         for (int i = 0; i < components.Count; i++)
         {
             var com = components[i];
             if (com != null)
             {
                 if (com.IsChanged)
                 {
                     com.Apply();
                 }
                 else
                 {
                     TextElement txt = com as TextElement;
                     if (txt != null)
                     {
                         txt.LoadTextSize();
                     }
                 }
             }
         }
         for (int i = 0; i < child.Count; i++)
         {
             child[i].Apply();
         }
         Context.gameObject.SetActive(true);
     }
     else
     {
         if (Context != null)
         {
             Context.gameObject.SetActive(false);
         }
     }
 }
        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);
        }