示例#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
        /// <summary>
        /// 快速设置图片的内容
        /// </summary>
        /// <param name="image"></param>
        /// <param name="graph"></param>
        public static void SetPictureOrLoadColor(Data.ImgNode image, UnityEngine.UI.Graphic graph)
        {
            graph.color = image.color;
            switch (image.type)
            {
            case ImgType.Image:
                ((UnityEngine.UI.Image)graph).sprite = image.sprite;
                break;

            case ImgType.Texture:
                ((UnityEngine.UI.RawImage)graph).texture = image.texture;
                break;

            case ImgType.Label:
                var myText = (UnityEngine.UI.Text)graph;
                myText.text     = image.text;
                myText.fontSize = image.fontSize;
                break;

            case ImgType.AtlasImage:
                ((UnityEngine.UI.Image)graph).sprite = image.sprite;
                break;

            default:
                break;
            }
        }
        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);
                    }
                }
            }
        }
示例#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);
                }
            }
        }
示例#5
0
        /// <summary>
        /// 初始化按扭为text或image
        /// </summary>
        /// <param name="image"></param>
        /// <param name="button"></param>
        private void InitButton(Data.ImgNode image, UnityEngine.UI.Button button)
        {
            if (image.type == ImgType.Label)
            {
                var text = button.GetComponent <UnityEngine.UI.Text>();
                if (text == null)
                {
                    text = button.gameObject.AddComponent <UnityEngine.UI.Text>();

                    button.targetGraphic = text;

                    SetRectTransform(image.rect, text.rectTransform);
#if UNITY_EDITOR
                    UnityEditorInternal.ComponentUtility.MoveComponentUp(text);
#endif
                }
            }
            else
            {
                var img = button.GetComponent <UnityEngine.UI.Image>();
                if (img == null)
                {
                    img = button.gameObject.AddComponent <UnityEngine.UI.Image>();
                    button.targetGraphic = img;
#if UNITY_EDITOR
                    UnityEditorInternal.ComponentUtility.MoveComponentUp(img);
#endif
                }
            }
        }
示例#6
0
 /// <summary>
 /// 设置图片切换规则
 /// </summary>
 /// <param name="image"></param>
 /// <param name="button"></param>
 private void SetSpriteSwipe(Data.ImgNode image, UnityEngine.UI.Button button)
 {
     if (MatchAddress(image.Name, normalAddress))
     {
         if (image.type == ImgType.Label)
         {
             (button.targetGraphic as UnityEngine.UI.Text).text = image.text;
         }
         else
         {
             button.image.sprite = image.sprite;
         }
     }
     else if (MatchAddress(image.Name, pressedAddress))
     {
         button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
         UnityEngine.UI.SpriteState state = button.spriteState;
         state.pressedSprite = image.sprite;
         button.spriteState  = state;
     }
     else if (MatchAddress(image.Name, disableAddress))
     {
         button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
         UnityEngine.UI.SpriteState state = button.spriteState;
         state.disabledSprite = image.sprite;
         button.spriteState   = state;
     }
     else if (MatchAddress(image.Name, highlightedAddress))
     {
         button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
         UnityEngine.UI.SpriteState state = button.spriteState;
         state.highlightedSprite = image.sprite;
         button.spriteState      = state;
     }
 }
示例#7
0
        private void DrawBackground(Data.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);
        }
示例#8
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);
        }
示例#9
0
        public UGUINode DrawRawImage(Data.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);
        }
示例#10
0
        private void DrawFill(Data.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>();
        }
示例#11
0
 public override UGUINode DrawImage(Data.ImgNode image, UGUINode parent)
 {
     if (image.type == ImgType.Texture)
     {
         return(DrawRawImage(image, parent));
     }
     else
     {
         return(DrawSpriteImage(image, parent));
     }
 }
示例#12
0
        public UGUINode DrawImage(Data.ImgNode image, UGUINode parent)
        {
            UGUINode node = imgImporterDic[image.type].DrawImage(image, parent);

            if (node == null)
            {
                Debug.Log(image.type);
                Debug.Log(image);
                Debug.Log(parent);
            }
            return(node);
        }
示例#13
0
        private void DrawImages(Data.GroupNode layer, UGUINode node, ScrollRect scrollRect)
        {
            for (int i = 0; i < layer.images.Count; i++)
            {
                Data.ImgNode image = layer.images[i];

                if (MatchAddress(image.Name, backgroundAddress))
                {
                    InitScrollViewBackground(node, image, scrollRect);
                }
                else
                {
                    ctrl.DrawImage(image, node);
                }
            }
        }
示例#14
0
        public override UGUINode DrawLayer(Data.GroupNode layer, UGUINode parent)
        {
            var node = base.CreateRootNode(layer.displayName, layer.rect, parent);

            UnityEngine.UI.Button button = node.InitComponent <UnityEngine.UI.Button>();

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

                    if (MatchAddress(image.Name, normalAddress, pressedAddress, disableAddress, highlightedAddress))
                    {
                        if (MatchAddress(image.Name, normalAddress))
                        {
                            SetRectTransform(image.rect, button.transform as RectTransform);
                        }

                        InitButton(image, button);

                        if (image.type == ImgType.Color)
                        {
                            SetColorSwipe(image, button);
                        }
                        else
                        {
                            SetSpriteSwipe(image, button);
                        }
                    }
                    else
                    {
                        if (autoButtonTitle && image.type == ImgType.Label && !image.Name.StartsWith(titleAddress))
                        {
                            var array = layer.images.Where(x => x.type == ImgType.Label).ToList();
                            if (array.Count > 0 && array.IndexOf(image) == 0)
                            {
                                image.Name = titleAddress + image.Name;
                            }
                        }

                        ctrl.DrawImage(image, node);
                    }
                }
            }
            return(node);
        }
示例#15
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);
            };
        }
示例#16
0
        /// <summary>
        /// 设置颜色切换规则
        /// </summary>
        /// <param name="image"></param>
        /// <param name="button"></param>
        private void SetColorSwipe(Data.ImgNode image, UnityEngine.UI.Button button)
        {
            Color color = image.color;

            if (MatchAddress(image.Name, normalAddress))
            {
                if (image.type == ImgType.Label)
                {
                    (button.targetGraphic as UnityEngine.UI.Text).text = image.text;
                }

                RectTransform rectTransform = button.GetComponent <RectTransform>();
                rectTransform.sizeDelta        = new Vector2(image.rect.width, image.rect.height);
                rectTransform.anchoredPosition = new Vector2(image.rect.x, image.rect.y);

                button.targetGraphic.color = color;
                button.transition          = UnityEngine.UI.Selectable.Transition.ColorTint;
                UnityEngine.UI.ColorBlock state = button.colors;
                state.normalColor = color;
                button.colors     = state;
            }
            else if (MatchAddress(image.Name, pressedAddress))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.ColorTint;
                UnityEngine.UI.ColorBlock state = button.colors;
                state.pressedColor = color;
                button.colors      = state;
            }
            else if (MatchAddress(image.Name, disableAddress))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.ColorTint;
                UnityEngine.UI.ColorBlock state = button.colors;
                state.disabledColor = color;
                button.colors       = state;
            }
            else if (MatchAddress(image.Name, highlightedAddress))
            {
                button.transition = UnityEngine.UI.Selectable.Transition.ColorTint;
                UnityEngine.UI.ColorBlock state = button.colors;
                state.highlightedColor = color;
                button.colors          = state;
            }
        }
示例#17
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);
         }
     }
 }
示例#18
0
        /// <summary>
        /// 将图层解析为imgNode
        /// </summary>
        /// <param name="rootSize"></param>
        /// <param name="layer"></param>
        /// <param name="forceSprite"></param>
        /// <returns></returns>
        public static Data.ImgNode AnalysisLayer(string baseName, Vector2 rootSize, PsdLayer layer, bool forceSprite = false)
        {
            Data.ImgNode data    = null;
            var          texture = CreateTexture(layer);
            var          rect    = GetRectFromLayer(layer);

            switch (layer.LayerType)
            {
            case LayerType.Normal:
                data = new Data.ImgNode(baseName, rect, texture).SetIndex(CalcuteLayerID(layer)).Analyzing(ExportUtility.RuleObj, layer.Name);
                break;

            case LayerType.Color:
                if (forceSprite)
                {
                    data = new Data.ImgNode(baseName, rect, texture).SetIndex(CalcuteLayerID(layer)).Analyzing(ExportUtility.RuleObj, layer.Name);
                }
                else
                {
                    data = new Data.ImgNode(layer.Name, rect, GetLayerColor(layer)).SetIndex(CalcuteLayerID(layer));
                }
                break;

            case LayerType.Text:
                var textInfo = layer.Records.TextInfo;
                var color    = new Color(textInfo.color[0], textInfo.color[1], textInfo.color[2], textInfo.color[3]);
                data = new Data.ImgNode(layer.Name, rect, textInfo.fontName, textInfo.fontSize, textInfo.text, color);
                break;

            case LayerType.Complex:
                if (!RuleObj.forceSprite)
                {
                    Debug.LogError("you psd have some not supported layer.(defult layer is not supported)! \n make sure your layers is Intelligent object or color lump." + "\n ->Detail:" + layer.Name);
                }
                data = new Data.ImgNode(baseName, rect, texture).SetIndex(CalcuteLayerID(layer)).Analyzing(ExportUtility.RuleObj, layer.Name);
                break;

            default:
                break;
            }
            return(data);
        }
示例#19
0
        private void DrawOtherLayers(Data.GroupNode layer, UGUINode node)
        {
            for (int imageIndex = 0; imageIndex < layer.images.Count; imageIndex++)
            {
                Data.ImgNode image = layer.images[imageIndex];
                if (!MatchAddress(image.Name, backgroundAddress, maskAddress))
                {
                    if (autoToggleTitle && image.type == ImgType.Label && !image.Name.StartsWith(titleAddress))
                    {
                        var array = layer.images.Where(x => x.type == ImgType.Label).ToList();
                        if (array.Count > 0 && array.IndexOf(image) == 0)
                        {
                            image.Name = titleAddress + image.Name;
                        }
                    }

                    ctrl.DrawImage(image, node);
                }
            }
        }
示例#20
0
        /// <summary>
        /// 转换为组
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="group"></param>
        /// <param name="OnRetrive"></param>
        public static void RetriveLayerToSwitchModle(Vector2 rootSize, PsdLayer layer, GroupNodeItem group, bool forceSprite = false)
        {
            if (!layer.IsGroup)
            {
                return;
            }
            else
            {
                float index = 0;
                foreach (var child in layer.Childs)
                {
                    var progress = ++index / layer.Childs.Length;
                    EditorUtility.DisplayProgressBar(layer.Name, "转换进度:" + progress, progress);

                    if (child.IsGroup)
                    {
                        GroupNodeItem childNode = new GroupNodeItem(GetRectFromLayer(child), idSpan++, group.depth + 1);
                        childNode.Analyzing(RuleObj, child.Name);
                        group.AddChild(childNode);

                        if (childNode != null)
                        {
                            RetriveLayerToSwitchModle(rootSize, child, childNode, forceSprite);
                        }
                    }

                    else
                    {
                        Data.ImgNode imgnode = AnalysisLayer(group.displayName, rootSize, child, forceSprite);
                        if (imgnode != null)
                        {
                            group.images.Add(imgnode);
                        }
                    }
                }
                EditorUtility.ClearProgressBar();
            }
        }
示例#21
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>());
 }
示例#22
0
 public abstract UGUINode DrawImage(Data.ImgNode image, UGUINode parent);