Exemplo n.º 1
0
        /// <summary>
        /// 绘制图片
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="node"></param>
        /// <param name="background"></param>
        private void DrawImages(Data.GroupNode layer, UGUINode node, out Graphic background)
        {
            background = null;
            for (int i = 0; i < layer.images.Count; i++)
            {
                Data.ImgNode image = layer.images[i];

                if (MatchAddress(image.Name, backgroundAddress))
                {
                    if (image.type == ImgType.Texture)
                    {
                        background = node.InitComponent <UnityEngine.UI.RawImage>();
                    }
                    else
                    {
                        background = node.InitComponent <UnityEngine.UI.Image>();
                    }

                    if (background)
                    {
                        PSDImporterUtility.SetPictureOrLoadColor(image, background);
                        SetRectTransform(image.rect, background.GetComponent <RectTransform>());
                        background.name = layer.displayName;
                    }
                }
                else
                {
                    ctrl.DrawImage(image, node);
                }
            }
        }
Exemplo n.º 2
0
        private void DrawImages(InputField inputfield, UGUINode node, Data.GroupNode layer)
        {
            if (layer.images != null)
            {
                for (int i = 0; i < layer.images.Count; i++)
                {
                    Data.ImgNode image = layer.images[i];

                    if (image.type == ImgType.Label && MatchAddress(image.Name, titleAddress))
                    {
                        UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.textComponent;//inputfield.transform.Find("Text").GetComponent<UnityEngine.UI.Text>();
                        var childNode            = CreateNormalNode(text.gameObject, image.rect, node);
                        childNode.anchoType = AnchoType.XStretch | AnchoType.YStretch;
                        PSDImporterUtility.SetPictureOrLoadColor(image, text);
                    }
                    else if (image.type == ImgType.Label && MatchAddress(image.Name, placeAddress))
                    {
                        UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.placeholder;//.transform.Find("Placeholder").GetComponent<UnityEngine.UI.Text>();
                        var childNode            = CreateNormalNode(text.gameObject, image.rect, node);
                        childNode.anchoType = AnchoType.XStretch | AnchoType.YStretch;
                        PSDImporterUtility.SetPictureOrLoadColor(image, text);
                    }
                    else if (MatchAddress(image.Name, backgroundAddress))
                    {
                        PSDImporterUtility.SetPictureOrLoadColor(image, inputfield.image);
                        SetRectTransform(image.rect, inputfield.GetComponent <RectTransform>());
                    }
                    else
                    {
                        ctrl.DrawImage(image, node);
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void AfterGenerate(UGUINode node)
        {
            base.AfterGenerate(node);
            var scrollbar = node.InitComponent <Scrollbar>();

            PSDImporterUtility.SetCustomAnchor(scrollbar.GetComponent <RectTransform>(), scrollbar.handleRect);
        }
Exemplo n.º 4
0
        private void DrawImages(List <Data.ImgNode> images, Scrollbar scrollbar, UGUINode node)
        {
            for (int i = 0; i < images.Count; i++)
            {
                Data.ImgNode         image = images[i];
                UnityEngine.UI.Image graph = null;

                if (MatchAddress(image.Name, backgroundAddress))
                {
                    graph = scrollbar.GetComponent <UnityEngine.UI.Image>();
                    SetRectTransform(image.rect, scrollbar.GetComponent <RectTransform>());
                }
                else if (MatchAddress(image.Name, handleAddress))
                {
                    graph = scrollbar.handleRect.GetComponent <UnityEngine.UI.Image>();
                }
                else
                {
                    ctrl.DrawImage(image, node);
                }

                if (graph != null)
                {
                    PSDImporterUtility.SetPictureOrLoadColor(image, graph);
                }
            }
        }
Exemplo n.º 5
0
        private void DrawMask(Data.GroupNode layer, Toggle toggle, UGUINode bgNode)
        {
            var mask = layer.images.Find(x => MatchAddress(x.Name, maskAddress));

            if (mask != null)
            {
                if (mask.sprite != null)
                {
                    SetGraphic <Image>(toggle);
                }
                else if (mask.texture != null)
                {
                    SetGraphic <RawImage>(toggle);
                }
                else if (mask.text != null)
                {
                    var text = SetGraphic <Text>(toggle);
                    text.horizontalOverflow = HorizontalWrapMode.Overflow;
                    text.verticalOverflow   = VerticalWrapMode.Overflow;
                }

                PSDImporterUtility.SetPictureOrLoadColor(mask, toggle.graphic);
                var graphic = toggle.targetGraphic.transform.Find("Mask").gameObject;
                CreateNormalNode(graphic, mask.rect, bgNode);
            }
            else
            {
                SetGraphic <Image>(toggle);
            }
        }
Exemplo n.º 6
0
 public void BeginSetAnchers(UGUINode node)
 {
     foreach (var item in node.childs)
     {
         BeginSetAnchers(item);
         PSDImporterUtility.SetAnchorByNode(item);
     }
 }
Exemplo n.º 7
0
        private void DrawBackground(ImgNode bg, UGUINode node)
        {
            var bgnode = ctrl.DrawImage(bg, node);
            var graph  = bgnode.InitComponent <UnityEngine.UI.Image>();

            node.InitComponent <Slider>().targetGraphic = graph;
            PSDImporterUtility.SetPictureOrLoadColor(bg, graph);
        }
Exemplo n.º 8
0
        public override UGUINode DrawImage(ImgNode image, UGUINode parent)
        {
            UGUINode node = CreateRootNode(image.Name, image.rect, parent);

            UnityEngine.UI.RawImage pic = node.InitComponent <UnityEngine.UI.RawImage>();
            PSDImporterUtility.SetPictureOrLoadColor(image, pic);
            return(node);
        }
Exemplo n.º 9
0
        public override UGUINode DrawImage(Data.ImgNode image, UGUINode parent)
        {
            UGUINode node = CreateRootNode(image.Name, AdjustTextRect(image.rect, image.fontSize), parent);

            UnityEngine.UI.Text myText = node.InitComponent <Text>();
            PSDImporterUtility.SetPictureOrLoadColor(image, myText);
            return(node);
        }
Exemplo n.º 10
0
        private void DrawMask(Data.GroupNode layer, Toggle toggle, UGUINode bgNode)
        {
            var mask = layer.images.Find(x => MatchAddress(x.Name, maskAddress));

            if (mask != null)
            {
                PSDImporterUtility.SetPictureOrLoadColor(mask, toggle.graphic);
                CreateNormalNode(toggle.graphic.gameObject, mask.rect, bgNode);
            }
        }
Exemplo n.º 11
0
        public override GameObject CreateTemplate()
        {
            var dropdown = new GameObject("DropDown", typeof(Dropdown), typeof(Image)).GetComponent <Dropdown>();
            var label    = new GameObject("Label", typeof(Text)).GetComponent <Text>();
            var template = new GameObject("Template", typeof(ScrollRect), typeof(Image)).GetComponent <ScrollRect>();
            var viewport = new GameObject("Viewport", typeof(Image), typeof(Mask)).GetComponent <Image>();
            var content  = new GameObject("Content", typeof(RectTransform)).GetComponent <RectTransform>();
            var item     = new GameObject("Item", typeof(Toggle)).GetComponent <Toggle>();
            var item_bg  = new GameObject("Item Background", typeof(Image)).GetComponent <Image>();
            var item_cm  = new GameObject("Item CheckMask", typeof(Image)).GetComponent <Image>();
            var item_lb  = new GameObject("Item Label", typeof(Text)).GetComponent <Text>();

            label.transform.SetParent(dropdown.transform, false);
            template.transform.SetParent(dropdown.transform, false);
            viewport.transform.SetParent(template.transform, false);
            content.transform.SetParent(viewport.transform, false);
            item.transform.SetParent(content.transform, false);
            item_bg.transform.SetParent(item.transform, false);
            item_bg.transform.SetParent(item.transform, false);
            item_cm.transform.SetParent(item.transform, false);
            item_lb.transform.SetParent(item.transform, false);

            dropdown.targetGraphic = dropdown.GetComponent <Image>();
            dropdown.captionText   = label;
            dropdown.template      = template.transform as RectTransform;
            dropdown.itemText      = item_lb;

            template.viewport = viewport.transform as RectTransform;
            template.content  = content;

            item.targetGraphic = item_bg;
            item.graphic       = item_cm;

            PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, dropdown.transform as RectTransform, label.transform as RectTransform);
            PSDImporterUtility.SetNormalAnchor(AnchoType.XCenter | AnchoType.YCenter, dropdown.transform as RectTransform, template.transform as RectTransform);
            PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, template.transform as RectTransform, viewport.transform as RectTransform);
            PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.Up, viewport.transform as RectTransform, content.transform as RectTransform);
            PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, content.transform as RectTransform, item.transform as RectTransform);
            PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, item.transform as RectTransform, item_bg.transform as RectTransform);
            PSDImporterUtility.SetNormalAnchor(AnchoType.Left | AnchoType.YCenter, item.transform as RectTransform, item_cm.transform as RectTransform);
            PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, item.transform as RectTransform, item_lb.transform as RectTransform);

            (template.transform as RectTransform).pivot = new Vector2(0.5f, 0.5f);
            content.pivot     = new Vector2(0.5f, 1);
            content.sizeDelta = new Vector2(0, content.sizeDelta.y);
            (item_bg.transform as RectTransform).sizeDelta = Vector2.zero;
            (item_cm.transform as RectTransform).sizeDelta = new Vector2(20, 20);
            (item_lb.transform as RectTransform).sizeDelta = Vector2.zero;

            item_lb.alignment = label.alignment = TextAnchor.MiddleCenter;
            viewport.GetComponent <Image>().color = new Color(0, 0, 0, 0.1f);
            item_cm.enabled = false;
            return(dropdown.gameObject);
        }
Exemplo n.º 12
0
        protected void StretchTitle(UGUINode node)
        {
            var texts = node.transform.GetComponentsInChildren <Text>();
            var title = Array.Find(texts, x => MatchAddress(x.name, rule.titleAddress));

            if (title)
            {
                PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, node.transform as RectTransform, title.transform as RectTransform);
                title.rectTransform.anchoredPosition = Vector3.zero;
            }
        }
Exemplo n.º 13
0
        protected void StretchTitle(UGUINode node)
        {
            var texts = node.transform.GetComponentsInChildren <Text>();

            var title = Array.Find(texts, x => MatchAddress(x.name, titleAddress));

            if (title)
            {
                PSDImporterUtility.SetNormalAnchor(AnchoType.XStretch | AnchoType.YStretch, node.transform as RectTransform, title.transform as RectTransform);
                title.rectTransform.anchoredPosition = Vector3.zero;
                title.alignment          = TextAnchor.MiddleCenter;
                title.horizontalOverflow = HorizontalWrapMode.Overflow;
                title.verticalOverflow   = VerticalWrapMode.Truncate;
            }
        }
Exemplo n.º 14
0
        private UGUINode DrawBackground(Data.GroupNode layer, Toggle toggle, UGUINode node)
        {
            var bgImage = layer.images.Find(x => MatchAddress(x.Name, backgroundAddress));

            UGUINode bgNode = null;

            if (bgImage != null)
            {
                bgNode = CreateNormalNode(toggle.targetGraphic.gameObject, bgImage.rect, node);
                PSDImporterUtility.SetPictureOrLoadColor(bgImage, toggle.targetGraphic);
                SetRectTransform(bgImage.rect, toggle.GetComponent <RectTransform>());
            }
            else
            {
                bgNode = CreateNormalNode(toggle.targetGraphic.gameObject, layer.rect, node);
            }
            return(bgNode);
        }
Exemplo n.º 15
0
 /// <summary>
 /// 绘制所有image
 /// </summary>
 /// <param name="node"></param>
 /// <param name="layer"></param>
 /// <param name="dropdown"></param>
 /// <param name="toggle"></param>
 /// <param name="content"></param>
 private void DrawImages(UGUINode node, Data.GroupNode layer, Dropdown dropdown, Toggle toggle, RectTransform content)
 {
     for (int i = 0; i < layer.images.Count; i++)
     {
         Data.ImgNode image = layer.images[i];
         if (MatchIDAddress(image.Name, 1, backgroundsFormat))
         {
             PSDImporterUtility.SetPictureOrLoadColor(image, dropdown.image);
             SetRectTransform(image.rect, dropdown.GetComponent <RectTransform>());
             dropdown.name = layer.displayName;
         }
         else if (MatchIDAddress(image.Name, 2, backgroundsFormat))
         {
             PSDImporterUtility.SetPictureOrLoadColor(image, dropdown.template.GetComponent <Graphic>());
             SetRectTransform(image.rect, dropdown.template);
         }
         else if (MatchIDAddress(image.Name, 3, backgroundsFormat))
         {
             UnityEngine.UI.Image itemimage = (UnityEngine.UI.Image)toggle.targetGraphic;
             PSDImporterUtility.SetPictureOrLoadColor(image, itemimage);
             content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, image.rect.height);
         }
         else if (MatchIDAddress(image.Name, 1, titlesFormat))
         {
             PSDImporterUtility.SetPictureOrLoadColor(image, dropdown.captionText);
         }
         else if (MatchIDAddress(image.Name, 2, titlesFormat))
         {
             PSDImporterUtility.SetPictureOrLoadColor(image, dropdown.itemText);
         }
         else if (MatchAddress(image.Name, maskAddress))
         {
             UnityEngine.UI.Image mask = (UnityEngine.UI.Image)toggle.graphic;
             mask.enabled = true;
             PSDImporterUtility.SetPictureOrLoadColor(image, mask);
         }
         else
         {
             ctrl.DrawImage(image, node);
         }
     }
 }
Exemplo n.º 16
0
        private UGUINode DrawBackground(Data.GroupNode layer, Toggle toggle, UGUINode node)
        {
            var bgImage = layer.images.Find(x => MatchAddress(x.Name, backgroundAddress));

            UGUINode bgNode = null;

            if (bgImage != null)
            {
                var targetGraphic = toggle.transform.Find("Background").gameObject;

                if (bgImage.sprite != null)
                {
                    SetTargetGraphic <Image>(toggle);
                }
                else if (bgImage.texture != null)
                {
                    SetTargetGraphic <RawImage>(toggle);
                }
                else if (bgImage.text != null)
                {
                    var text = SetTargetGraphic <Text>(toggle);
                    text.horizontalOverflow = HorizontalWrapMode.Overflow;
                    text.verticalOverflow   = VerticalWrapMode.Overflow;
                }

                bgNode = CreateNormalNode(targetGraphic, bgImage.rect, node);
                PSDImporterUtility.SetPictureOrLoadColor(bgImage, toggle.targetGraphic);
                SetRectTransform(bgImage.rect, toggle.GetComponent <RectTransform>());
            }
            else
            {
                SetTargetGraphic <Image>(toggle);
                bgNode = CreateNormalNode(toggle.targetGraphic.gameObject, layer.rect, node);
            }
            return(bgNode);
        }
Exemplo n.º 17
0
        public override GameObject CreateTemplate()
        {
            var inputfield = new GameObject("InputField", typeof(InputField), typeof(Image)).GetComponent <InputField>();
            var holder     = new GameObject("Placeholder", typeof(RectTransform), typeof(Text)).GetComponent <Text>();
            var text       = new GameObject("Text", typeof(Text)).GetComponent <Text>();

            inputfield.targetGraphic = inputfield.GetComponent <Image>();

            holder.transform.SetParent(inputfield.transform, false);
            text.transform.SetParent(inputfield.transform, false);

            //设置默认锚点
            PSDImporterUtility.SetCustomAnchor(inputfield.GetComponent <RectTransform>(), holder.rectTransform);
            PSDImporterUtility.SetCustomAnchor(inputfield.GetComponent <RectTransform>(), text.rectTransform);

            inputfield.GetComponent <InputField>().placeholder = holder;
            holder.alignment       = TextAnchor.MiddleLeft;
            holder.supportRichText = false;
            Color color;

            if (ColorUtility.TryParseHtmlString("#32323280", out color))
            {
                holder.color = color;
            }

            inputfield.GetComponent <InputField>().textComponent = text;
            text.alignment          = TextAnchor.MiddleLeft;
            text.horizontalOverflow = HorizontalWrapMode.Wrap;
            text.verticalOverflow   = VerticalWrapMode.Overflow;
            text.supportRichText    = false;
            if (ColorUtility.TryParseHtmlString("#32323280", out color))
            {
                text.color = color;
            }
            return(inputfield.gameObject);
        }
Exemplo n.º 18
0
 private void InitScrollViewBackground(UGUINode node, Data.ImgNode image, ScrollRect scrollRect)
 {
     UnityEngine.UI.Image graph = node.InitComponent <UnityEngine.UI.Image>();
     PSDImporterUtility.SetPictureOrLoadColor(image, graph);
     SetRectTransform(image.rect, scrollRect.GetComponent <RectTransform>());
 }