コード例 #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);
                }
            }
        }
コード例 #2
0
        private void DrawChildLayers(Data.GroupNode layer, UGUINode viewNode, ScrollRect scrollRect)
        {
            if (layer.children != null)
            {
                for (int i = 0; i < layer.children.Count; i++)
                {
                    Data.GroupNode child     = layer.children[i] as Data.GroupNode;
                    UGUINode       childNode = ctrl.DrawLayer(child, viewNode);

                    if (MatchAddress(child.displayName, contentAddress))
                    {
                        DrawConent(childNode, scrollRect);
                    }
                    else if (MatchAddress(child.displayName, vbarAddress))
                    {
                        scrollRect.verticalScrollbar           = childNode.InitComponent <Scrollbar>();
                        scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
                        childNode.anchoType = AnchoType.Right | AnchoType.YCenter;
                    }
                    else if (MatchAddress(child.displayName, hbarAddress))
                    {
                        scrollRect.horizontalScrollbar           = childNode.InitComponent <Scrollbar>();
                        scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
                        childNode.anchoType = AnchoType.Down | AnchoType.XCenter;
                    }
                }
            }
        }
コード例 #3
0
        public override void AfterGenerate(UGUINode node)
        {
            base.AfterGenerate(node);
            var scrollbar = node.InitComponent <Scrollbar>();

            PSDImporterUtility.SetCustomAnchor(scrollbar.GetComponent <RectTransform>(), scrollbar.handleRect);
        }
コード例 #4
0
        public override UGUINode DrawLayer(GroupNode layer, UGUINode parent)
        {
            UGUINode node = CreateRootNode(layer.displayName, layer.rect, parent); //GameObject.Instantiate(temp) as UnityEngine.UI.Slider;

            UnityEngine.UI.Slider slider = node.InitComponent <UnityEngine.UI.Slider>();
            SetSliderDirection(slider, layer);
            for (int i = 0; i < layer.images.Count; i++)
            {
                var imgNode = layer.images[i];
                if (MatchAddress(imgNode.Name, rule.backgroundAddress))
                {
                    DrawBackground(imgNode, node);
                }
                else if (MatchAddress(imgNode.Name, rule.fillAddress))
                {
                    DrawFill(imgNode, node);
                }
                else if (MatchAddress(imgNode.Name, rule.handleAddress))
                {
                    DrawHandle(imgNode, node, layer);
                }
                else
                {
                    ctrl.DrawImage(imgNode, node);
                }
            }
            return(node);
        }
コード例 #5
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);
        }
コード例 #6
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode node = CreateRootNode(layer.displayName, layer.rect, parent);

            UnityEngine.UI.InputField inputfield = node.InitComponent <UnityEngine.UI.InputField>();
            DrawImages(inputfield, node, layer);
            return(node);
        }
コード例 #7
0
ファイル: TextImport.cs プロジェクト: willhome/unity-psd
        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);
        }
コード例 #8
0
        public override void AfterGenerate(UGUINode node)
        {
            base.AfterGenerate(node);
            ContentSizeFitter content = node.InitComponent <ContentSizeFitter>();

            content.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
            content.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
        }
コード例 #9
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);
        }
コード例 #10
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode  node      = CreateRootNode(layer.displayName, layer.rect, parent);
            Scrollbar scrollbar = node.InitComponent <Scrollbar>();

            SetScrollBarDirection(scrollbar, layer);
            DrawImages(layer.images, scrollbar, node);
            return(node);
        }
コード例 #11
0
        public override void AfterGenerate(UGUINode node)
        {
            base.AfterGenerate(node);
            var           dropDown = node.InitComponent <Dropdown>();
            RectTransform rt       = dropDown.template;

            rt.pivot            = new Vector2(0.5f, 1);
            rt.anchoredPosition = Vector3.zero;
        }
コード例 #12
0
 /// <summary>
 /// 空器
 /// </summary>
 /// <param name="childNode"></param>
 /// <param name="scrollRect"></param>
 private void DrawConent(UGUINode childNode, ScrollRect scrollRect)
 {
     childNode.inversionReprocess += (x) =>
     {
         var content = childNode.InitComponent <RectTransform>();
         scrollRect.content = content;
         scrollRect.content.anchoredPosition = Vector2.zero;
     };
 }
コード例 #13
0
        private void DrawFill(ImgNode fill, UGUINode node)
        {
            var fillAreaNode = CreateNormalNode(new GameObject("Fill Area", typeof(RectTransform)), fill.rect, node);
            var fileNode     = ctrl.DrawImage(fill, fillAreaNode);

            fileNode.InitComponent <Image>().type = Image.Type.Tiled;

            node.InitComponent <Slider>().fillRect = fileNode.InitComponent <RectTransform>();
        }
コード例 #14
0
        public override void AfterGenerate(UGUINode node)
        {
            base.AfterGenerate(node);
            var inputField = node.InitComponent <InputField>();
            var text       = inputField.textComponent.GetComponent <RectTransform>();
            var holder     = inputField.placeholder.GetComponent <RectTransform>();

            text.anchorMin        = holder.anchorMin = Vector2.zero;
            text.anchorMax        = holder.anchorMax = Vector2.one;
            text.anchoredPosition = holder.anchoredPosition = Vector2.zero;
            text.sizeDelta        = holder.sizeDelta = new Vector2(-10, -10);
        }
コード例 #15
0
        /// <summary>
        /// 初始化组
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="node"></param>
        private void InitLayoutGroup(GroupNode layer, UGUINode node)
        {
            HorizontalOrVerticalLayoutGroup group = null;

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

            case Direction.Vertical:
            default:
                group = node.InitComponent <UnityEngine.UI.VerticalLayoutGroup>();
                break;
            }
            if (group)
            {
                (group as UnityEngine.UI.VerticalLayoutGroup).spacing = layer.spacing;
                group.childAlignment = TextAnchor.UpperLeft;
            }
        }
コード例 #16
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode   node       = CreateRootNode(layer.displayName, layer.rect, parent);
            ScrollRect scrollRect = node.InitComponent <UnityEngine.UI.ScrollRect>();

            SetScrollViewDirection(layer, scrollRect, layer.directionAxis);
            var viewNode = DrawViewNode(layer, scrollRect, node);

            DrawImages(layer, node, scrollRect);
            DrawChildLayers(layer, viewNode, scrollRect);
            return(node);
        }
コード例 #17
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode node = CreateRootNode(layer.displayName, layer.rect, parent);

            UnityEngine.UI.Toggle toggle = node.InitComponent <UnityEngine.UI.Toggle>();
            if (layer.images != null)
            {
                var bgNode = DrawBackground(layer, toggle, node);
                DrawMask(layer, toggle, bgNode);
                DrawOtherLayers(layer, node);
            }
            return(node);
        }
コード例 #18
0
 /// <summary>
 /// 试图为Panel类型的图片添加空背景
 /// </summary>
 /// <param name="background"></param>
 /// <param name="layer"></param>
 /// <param name="node"></param>
 private void TryDrawPanel(Graphic background, Data.GroupNode layer, UGUINode node)
 {
     if (background == null)
     {
         background = node.InitComponent <UnityEngine.UI.Image>();
         SetRectTransform(layer.rect, background.GetComponent <RectTransform>());
         Color color;
         if (ColorUtility.TryParseHtmlString("#FFFFFF01", out color))
         {
             background.color = color;
         }
         background.name = layer.displayName;
     }
 }
コード例 #19
0
        /// <summary>
        /// 设置目标Anchor
        /// </summary>
        /// <param name="image"></param>
        /// <param name="rectTransform"></param>
        public static void SetAnchorByNode(UGUINode node)
        {
            RectTransform p_rt = node.parent.InitComponent <RectTransform>();
            RectTransform c_rt = node.InitComponent <RectTransform>();

            switch (node.anchoType)
            {
            case AnchoType.Custom:
                SetCustomAnchor(p_rt, c_rt);
                break;

            default:
                SetNormalAnchor(node.anchoType, p_rt, c_rt);
                break;
            }
        }
コード例 #20
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            UGUINode node = CreateRootNode(layer.displayName, layer.rect, parent);

            Dropdown      dropdown  = node.InitComponent <Dropdown>();
            ScrollRect    scrllRect = dropdown.template.GetComponent <ScrollRect>();
            RectTransform content   = scrllRect.content;
            Toggle        toggle    = content.GetComponentInChildren <Toggle>();

            UGUINode tempNode = CreateNormalNode(dropdown.template.gameObject, layer.rect, node);

            tempNode.anchoType = AnchoType.Down | AnchoType.XStretch;
            DrawImages(node, layer, dropdown, toggle, content);
            DrawSubLayers(layer, tempNode, scrllRect);
            return(node);
        }
コード例 #21
0
        private void DrawHandle(Data.ImgNode handle, UGUINode node, Data.GroupNode layer)
        {
            var slider = node.InitComponent <Slider>();

            Data.ImgNode bg   = layer.images.Find(x => MatchAddress(x.Name, backgroundAddress));
            Data.ImgNode fill = layer.images.Find(x => MatchAddress(x.Name, fillAddress));

            var tempRect     = fill != null ? fill : bg;
            var rect         = new Rect(tempRect.rect.x, tempRect.rect.y, tempRect.rect.width - handle.rect.width, tempRect.rect.height);//x,y 为中心点的坐标!
            var handAreaNode = CreateNormalNode(new GameObject("Handle Slide Area", typeof(RectTransform)), rect, node);
            var handNode     = ctrl.DrawImage(handle, handAreaNode);

            slider.handleRect = handNode.InitComponent <RectTransform>();

            ///设置handle最后的锚点类型
            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.inversionReprocess += (n) =>
            {
                //写slider进行关联后,尺寸信息丢失
                slider.handleRect.anchoredPosition = Vector3.zero;
                slider.handleRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, handle.rect.width);
                slider.handleRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, handle.rect.height);
            };
        }
コード例 #22
0
 /// <summary>
 /// 滑动条绘制
 /// </summary>
 /// <param name="layer"></param>
 /// <param name="tempNode"></param>
 /// <param name="scrollRect"></param>
 private void DrawSubLayers(Data.GroupNode layer, UGUINode tempNode, ScrollRect scrollRect)
 {
     if (layer.children != null)
     {
         for (int i = 0; i < layer.children.Count; i++)
         {
             Data.GroupNode child = layer.children[i] as Data.GroupNode;
             if (MatchAddress(child.displayName, vbarAddress))
             {
                 UGUINode barNode = ctrl.DrawLayer(child, tempNode);
                 scrollRect.verticalScrollbar           = barNode.InitComponent <Scrollbar>();
                 scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
                 barNode.anchoType = AnchoType.Right | AnchoType.YCenter;
             }
             else
             {
                 ctrl.DrawLayer(child, tempNode);
             }
         }
     }
 }
コード例 #23
0
        private void InitGrid(UGUINode node, GroupNode layer)
        {
            GridLayoutGroup gridLayoutGroup = node.InitComponent <GridLayoutGroup>();

            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;
        }
コード例 #24
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>());
 }
コード例 #25
0
ファイル: PSDImportCtrl.cs プロジェクト: willhome/unity-psd
        private void InitBaseSize(UGUINode uinode, Vector2 uiSize)
        {
            var rect = uinode.InitComponent <RectTransform>();

            rect.sizeDelta = uiSize;
        }