Example #1
0
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.GRID, layer.Name, parent);

            node.anchoType = AnchoType.Up | AnchoType.Left;
            GridLayoutGroup gridLayoutGroup = node.InitComponent <GridLayoutGroup>();

            PSDImportUtility.SetRectTransform(layer, gridLayoutGroup.GetComponent <RectTransform>());

            gridLayoutGroup.padding  = new RectOffset(1, 1, 1, 1);
            gridLayoutGroup.cellSize = new Vector2(layer.rect.width, layer.rect.height);

            switch (layer.direction)
            {
            case Direction.Horizontal:
                gridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedColumnCount;
                break;

            case Direction.Vertical:
                gridLayoutGroup.constraint = GridLayoutGroup.Constraint.FixedRowCount;
                break;

            default:
                gridLayoutGroup.constraint = GridLayoutGroup.Constraint.Flexible;
                break;
            }
            gridLayoutGroup.constraintCount = layer.constraintCount;

            ctrl.DrawImages(layer.images.ToArray(), node);
            ctrl.DrawLayers(layer.groups.ToArray() as GroupNode[], node);
            return(node);
        }
Example #2
0
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.TOGGLE, layer.Name, parent);// GameObject.Instantiate(temp) as UnityEngine.UI.Toggle;

            UnityEngine.UI.Toggle toggle = node.InitComponent <UnityEngine.UI.Toggle>();
            if (layer.images != null)
            {
                for (int imageIndex = 0; imageIndex < layer.images.Count; imageIndex++)
                {
                    ImgNode image     = layer.images[imageIndex];
                    string  lowerName = image.Name.ToLower();
                    if (lowerName.StartsWith("b_"))
                    {
                        PSDImportUtility.SetPictureOrLoadColor(image, toggle.targetGraphic);
                        PSDImportUtility.SetRectTransform(image, toggle.GetComponent <RectTransform>());
                    }
                    else if (lowerName.StartsWith("m_"))
                    {
                        PSDImportUtility.SetPictureOrLoadColor(image, toggle.graphic);
                    }
                    else
                    {
                        ctrl.DrawImage(image, node);
                    }
                }
            }
            return(node);
        }
Example #3
0
 public void BeginSetAnchers(UGUINode node)
 {
     foreach (var item in node.childs)
     {
         BeginSetAnchers(item);
         PSDImportUtility.SetAnchorByNode(item);
     }
 }
Example #4
0
        private UGUINode DrawRawImage(ImgNode image, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.RawIMAGE, image.sprite.name, parent);

            UnityEngine.UI.RawImage pic = node.InitComponent <UnityEngine.UI.RawImage>();
            PSDImportUtility.SetPictureOrLoadColor(image, pic);
            PSDImportUtility.SetRectTransform(image, pic.GetComponent <RectTransform>());
            return(node);
        }
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode  node      = PSDImportUtility.InstantiateItem(GroupType.SCROLLBAR, layer.Name, parent);
            Scrollbar scrollBar = node.InitComponent <Scrollbar>();

            switch (layer.direction)
            {
            case Direction.LeftToRight:
                scrollBar.direction = Scrollbar.Direction.LeftToRight;
                break;

            case Direction.BottomToTop:
                scrollBar.direction = Scrollbar.Direction.BottomToTop;
                break;

            case Direction.TopToBottom:
                scrollBar.direction = Scrollbar.Direction.TopToBottom;
                break;

            case Direction.RightToLeft:
                scrollBar.direction = Scrollbar.Direction.RightToLeft;
                break;

            default:
                break;
            }

            for (int i = 0; i < layer.images.Count; i++)
            {
                ImgNode image              = layer.images[i];
                string  lowerName          = image.Name.ToLower();
                UnityEngine.UI.Image graph = null;

                if (lowerName.StartsWith("b_"))
                {
                    graph = scrollBar.GetComponent <UnityEngine.UI.Image>();
                    PSDImportUtility.SetRectTransform(image, scrollBar.GetComponent <RectTransform>());
                    scrollBar.name = layer.Name;
                }
                else if (lowerName.StartsWith("h_"))
                {
                    graph = scrollBar.handleRect.GetComponent <UnityEngine.UI.Image>();
                }

                if (graph == null)
                {
                    //忽略Scorllbar其他的artLayer
                    continue;
                }

                PSDImportUtility.SetPictureOrLoadColor(image, graph);
            }
            return(node);
        }
Example #6
0
        public void BeginDrawUILayers(GroupNode1[] groups, Vector2 uiSize)
        {
            UGUINode      empty = PSDImportUtility.InstantiateItem(GroupType.EMPTY, "PSDUnity", PSDImportUtility.uinode);
            RectTransform rt    = empty.InitComponent <RectTransform>();

            rt.sizeDelta = new Vector2(uiSize.x, uiSize.y);
            for (int layerIndex = 0; layerIndex < groups.Length; layerIndex++)
            {
                DrawLayer(groups[layerIndex] as GroupNode, empty);
            }
            AssetDatabase.Refresh();
        }
Example #7
0
        public UGUINode DrawImage(ImgNode image, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.TEXT, image.Name, parent);

            UnityEngine.UI.Text myText = node.InitComponent <Text>();
            PSDImportUtility.SetPictureOrLoadColor(image, myText);
            RectTransform rectTransform = myText.GetComponent <RectTransform>();

            AdjustImage(image, myText.fontSize);
            rectTransform.sizeDelta        = new Vector2(image.rect.width, image.rect.height);
            rectTransform.anchoredPosition = new Vector2(image.rect.x, image.rect.y);
            return(node);
        }
Example #8
0
        public void Import(GroupNode1[] gourps, Vector2 uiSize)
        {
            BeginDrawUILayers(gourps, uiSize);
            BeginSetUIParents(PSDImportUtility.uinode);
            BeginSetAnchers(PSDImportUtility.uinode.childs[0]);

            //最外层的要单独处理
            var rp = PSDImportUtility.uinode.InitComponent <RectTransform>();
            var rt = PSDImportUtility.uinode.childs[0].InitComponent <RectTransform>();

            PSDImportUtility.SetNormalAnchor(AnchoType.XCenter | AnchoType.YCenter, rt, rp);

            BeginReprocess(PSDImportUtility.uinode.childs[0]);//后处理
        }
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.INPUTFIELD, layer.Name, parent);

            UnityEngine.UI.InputField inputfield = node.InitComponent <UnityEngine.UI.InputField>();

            if (layer.images != null)
            {
                for (int imageIndex = 0; imageIndex < layer.images.Count; imageIndex++)
                {
                    ImgNode image     = layer.images[imageIndex];
                    string  lowerName = image.Name.ToLower();

                    if (image.type == ImgType.Label)
                    {
                        if (lowerName.StartsWith("t_"))
                        {
                            UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.textComponent;//inputfield.transform.Find("Text").GetComponent<UnityEngine.UI.Text>();
                            PSDImportUtility.SetPictureOrLoadColor(image, text);
                        }
                        else if (lowerName.StartsWith("p_"))
                        {
                            UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.placeholder;//.transform.Find("Placeholder").GetComponent<UnityEngine.UI.Text>();
                            PSDImportUtility.SetPictureOrLoadColor(image, text);
                        }
                    }
                    else
                    {
                        if (lowerName.StartsWith("b_"))
                        {
                            PSDImportUtility.SetPictureOrLoadColor(image, inputfield.image);
                            PSDImportUtility.SetRectTransform(image, inputfield.GetComponent <RectTransform>());
                        }
                    }
                }
            }
            return(node);
        }
Example #10
0
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.IMAGE, layer.Name, parent);//GameObject.Instantiate(temp) as UnityEngine.UI.Image;

            UnityEngine.UI.Image panel = node.InitComponent <UnityEngine.UI.Image>();

            ctrl.DrawLayers(layer.groups.ToArray(), node);//子节点
            bool havebg = false;

            for (int i = 0; i < layer.images.Count; i++)
            {
                ImgNode image = layer.images[i];

                if (image.Name.ToLower().StartsWith("b_"))
                {
                    havebg = true;
                    PSDImportUtility.SetPictureOrLoadColor(image, panel);
                    PSDImportUtility.SetRectTransform(image, panel.GetComponent <RectTransform>());
                    panel.name = layer.Name;
                }
                else
                {
                    ctrl.DrawImage(image, node);
                }
            }
            if (!havebg)
            {
                PSDImportUtility.SetRectTransform(layer, panel.GetComponent <RectTransform>());
                Color color;
                if (ColorUtility.TryParseHtmlString("#FFFFFF01", out color))
                {
                    panel.GetComponent <UnityEngine.UI.Image>().color = color;
                }
                panel.name = layer.Name;
            }
            return(node);
        }
Example #11
0
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.BUTTON, layer.Name, parent);

            UnityEngine.UI.Button button = node.InitComponent <UnityEngine.UI.Button>();
            PSDImportUtility.SetRectTransform(layer, button.GetComponent <RectTransform>());

            if (layer.images != null)
            {
                for (int imageIndex = 0; imageIndex < layer.images.Count; imageIndex++)
                {
                    ImgNode image     = layer.images[imageIndex];
                    string  lowerName = image.Name.ToLower();
                    if (lowerName.StartsWith("n_") || lowerName.StartsWith("p_") || lowerName.StartsWith("d_") || lowerName.StartsWith("h_"))
                    {
                        if (lowerName.StartsWith("n_"))
                        {
                            PSDImportUtility.SetRectTransform(image, button.GetComponent <RectTransform>());
                        }
                        if (image.color == UnityEngine.Color.white)
                        {
                            SetSpriteSwipe(image, button);
                        }
                        else
                        {
                            SetColorSwipe(image, button);
                        }
                    }
                    else
                    {
                        ctrl.DrawImage(image, node);
                    }
                }
            }
            return(node);
        }
Example #12
0
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.GROUP, layer.Name, parent);

            UnityEngine.UI.LayoutGroup group = null;
            switch (layer.direction)
            {
            case Direction.Horizontal:
                group = node.InitComponent <UnityEngine.UI.HorizontalLayoutGroup>();
                group.childAlignment = TextAnchor.UpperLeft;
                break;

            case Direction.Vertical:
                group = node.InitComponent <UnityEngine.UI.VerticalLayoutGroup>();
                group.childAlignment = TextAnchor.UpperLeft;
                break;

            default:
                break;
            }
            ((UnityEngine.UI.VerticalLayoutGroup)group).spacing = layer.spacing;

            PSDImportUtility.SetRectTransform(layer, group.GetComponent <RectTransform>());

            UGUINode[] nodes = pSDImportCtrl.DrawImages(layer.images.ToArray(), node);
            foreach (var item in nodes)
            {
                item.anchoType = AnchoType.Left | AnchoType.Up;
            }
            nodes = pSDImportCtrl.DrawLayers(layer.groups.ToArray(), node);
            foreach (var item in nodes)
            {
                item.anchoType = AnchoType.Left | AnchoType.Up;
            }
            return(node);
        }
Example #13
0
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.SLIDER, layer.Name, parent); //GameObject.Instantiate(temp) as UnityEngine.UI.Slider;

            UnityEngine.UI.Slider slider = node.InitComponent <UnityEngine.UI.Slider>();
            PSDImportUtility.SetRectTransform(layer, slider.GetComponent <RectTransform>());
            slider.value = 1;

            ImgNode bg     = layer.images.Find(x => x.Name.ToLower().StartsWith("b_"));
            ImgNode fill   = layer.images.Find(x => x.Name.ToLower().StartsWith("f_"));
            ImgNode handle = layer.images.Find(x => x.Name.ToLower().StartsWith("h_"));

            if (bg != null)
            {
                var graph = node.InitComponent <UnityEngine.UI.Image>();
                PSDImportUtility.SetPictureOrLoadColor(bg, graph);
            }

            if (fill != null)
            {
                var fillAreaNode = PSDImportUtility.InstantiateItem(GroupType.EMPTY, "Fill Area", node);
                var fileNode     = ctrl.DrawImage(fill, fillAreaNode);
                fileNode.InitComponent <Image>().type = Image.Type.Tiled;
                PSDImportUtility.SetRectTransform(fill, fillAreaNode.InitComponent <RectTransform>());

                fillAreaNode.ReprocessEvent = () =>
                {
                    slider.fillRect = fileNode.InitComponent <RectTransform>();
                };
            }

            if (handle != null && bg != null)
            {
                var tempRect = fill != null ? fill : bg;
                SetSlider(slider, handle, layer);
                var handAreaNode = PSDImportUtility.InstantiateItem(GroupType.EMPTY, "Handle Slide Area", node);
                var handNode     = ctrl.DrawImage(handle, handAreaNode);
                PSDImportUtility.SetRectTransform(tempRect, handAreaNode.InitComponent <RectTransform>());

                switch (layer.direction)
                {
                case Direction.LeftToRight:
                    handNode.anchoType = AnchoType.Right | AnchoType.YStretch;
                    break;

                case Direction.BottomToTop:
                    handNode.anchoType = AnchoType.Up | AnchoType.XStretch;
                    break;

                case Direction.TopToBottom:
                    handNode.anchoType = AnchoType.Down | AnchoType.XStretch;
                    break;

                case Direction.RightToLeft:
                    handNode.anchoType = AnchoType.Left | AnchoType.YStretch;
                    break;

                default:
                    break;
                }
                handNode.ReprocessEvent = () =>
                {
                    slider.handleRect = handNode.InitComponent <RectTransform>();
                    slider.handleRect.anchoredPosition = Vector3.zero;
                };
            }
            else
            {
                SetSlider(slider, layer.direction);
            }


            return(node);
        }
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = PSDImportUtility.InstantiateItem(GroupType.SCROLLVIEW, layer.Name, parent);

            UnityEngine.UI.ScrollRect scrollRect = node.InitComponent <UnityEngine.UI.ScrollRect>();

            UGUINode childNode = PSDImportUtility.InstantiateItem(GroupType.IMAGE, "Viewport", node);

            scrollRect.viewport = childNode.InitComponent <RectTransform>();
            Color color;

            if (ColorUtility.TryParseHtmlString("#FFFFFF01", out color))
            {
                childNode.InitComponent <UnityEngine.UI.Image>().color = color;
            }
            childNode.InitComponent <Mask>();
            childNode.anchoType = AnchoType.XStretch | AnchoType.YStretch;

            bool havebg = false;

            for (int i = 0; i < layer.images.Count; i++)
            {
                ImgNode image = layer.images[i];

                if (image.Name.ToLower().StartsWith("b_"))
                {
                    havebg = true;
                    UnityEngine.UI.Image graph = node.InitComponent <UnityEngine.UI.Image>();

                    PSDImportUtility.SetPictureOrLoadColor(image, graph);

                    PSDImportUtility.SetRectTransform(image, scrollRect.GetComponent <RectTransform>());
                }
                else
                {
                    ctrl.DrawImage(image, node);
                }
            }

            if (!havebg)
            {
                PSDImportUtility.SetRectTransform(layer, scrollRect.GetComponent <RectTransform>());
            }

            PSDImportUtility.SetRectTransform(layer, childNode.InitComponent <RectTransform>());

            switch (layer.direction)
            {
            case Direction.Horizontal:
                scrollRect.vertical   = true;
                scrollRect.horizontal = false;
                break;

            case Direction.Vertical:
                scrollRect.vertical   = false;
                scrollRect.horizontal = true;
                break;

            case Direction.Horizontal | Direction.Vertical:
                scrollRect.vertical   = true;
                scrollRect.horizontal = true;
                break;

            default:
                break;
            }


            if (layer.groups != null)
            {
                for (int i = 0; i < layer.groups.Count; i++)
                {
                    GroupNode child          = layer.groups[i];
                    string    childLowerName = child.Name;
                    UGUINode  c_Node         = ctrl.DrawLayer(child, childNode);

                    if (childLowerName.StartsWith("c_"))
                    {
                        scrollRect.content = c_Node.InitComponent <RectTransform>();
                    }
                    else if (childLowerName.StartsWith("vb_"))
                    {
                        scrollRect.verticalScrollbar           = c_Node.InitComponent <Scrollbar>();
                        scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
                    }
                    else if (childLowerName.StartsWith("hb_"))
                    {
                        scrollRect.horizontalScrollbar           = c_Node.InitComponent <Scrollbar>();
                        scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
                    }
                }
            }
            return(node);
        }
        public UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode      node      = PSDImportUtility.InstantiateItem(GroupType.DROPDOWN, layer.Name, parent);
            Dropdown      dropdown  = node.InitComponent <Dropdown>();
            ScrollRect    scrllRect = dropdown.template.GetComponent <ScrollRect>();
            RectTransform content   = scrllRect.content;
            Toggle        toggle    = content.GetComponentInChildren <Toggle>();

            UGUINode childNode = new UGUINode(dropdown.template, node);

            childNode.transform.SetParent(PSDImportUtility.canvas.transform);
            childNode.anchoType = AnchoType.Down | AnchoType.XStretch;
            //由于设置相对坐标需要,所以修改了部分预制体的状态
            childNode.ReprocessEvent = () => {
                RectTransform rt = childNode.InitComponent <RectTransform>();
                rt.pivot            = new Vector2(0.5f, 1);
                rt.anchoredPosition = Vector3.zero;
            };
            for (int i = 0; i < layer.images.Count; i++)
            {
                ImgNode image     = layer.images[i];
                string  lowerName = image.Name.ToLower();
                if (lowerName.StartsWith("b1_"))
                {
                    PSDImportUtility.SetPictureOrLoadColor(image, dropdown.image);
                    PSDImportUtility.SetRectTransform(image, dropdown.GetComponent <RectTransform>());
                    dropdown.name = layer.Name;
                }
                else if (lowerName.StartsWith("b2_"))
                {
                    PSDImportUtility.SetPictureOrLoadColor(image, dropdown.template.GetComponent <Graphic>());
                    PSDImportUtility.SetRectTransform(image, dropdown.template);
                }
                else if (lowerName.StartsWith("b3_"))
                {
                    UnityEngine.UI.Image itemimage = (UnityEngine.UI.Image)toggle.targetGraphic;
                    PSDImportUtility.SetPictureOrLoadColor(image, itemimage);
                    content.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, image.rect.height);
                }
                else if (lowerName.StartsWith("t1_"))
                {
                    PSDImportUtility.SetPictureOrLoadColor(image, dropdown.captionText);
                }
                else if (lowerName.StartsWith("t2_"))
                {
                    PSDImportUtility.SetPictureOrLoadColor(image, dropdown.itemText);
                }
                else if (lowerName.StartsWith("m_"))
                {
                    UnityEngine.UI.Image mask = (UnityEngine.UI.Image)toggle.graphic;
                    PSDImportUtility.SetPictureOrLoadColor(image, mask);
                }
                else
                {
                    ctrl.DrawImage(image, node);
                }
            }

            for (int i = 0; i < layer.groups.Count; i++)
            {
                GroupNode child     = layer.groups[i] as GroupNode;
                string    lowerName = child.Name;
                if (lowerName.StartsWith("vb_"))
                {
                    UGUINode barNode = ctrl.DrawLayer(child, childNode);
                    scrllRect.verticalScrollbar           = barNode.InitComponent <Scrollbar>();
                    scrllRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
                }
                else
                {
                    ctrl.DrawLayer(child, node);
                }
            }

            return(node);
        }