示例#1
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            TabGroup tabGroup = PSDImportUtility.LoadAndInstant <TabGroup>(PSDImporterConst.ASSET_PATH_TABGROUP, layer.name, parent);

            if (layer.layers == null)
            {
                Debug.LogError("error! bad tabgroup layers.");
                return;
            }

            for (int index = 0; index < layer.layers.Length; index++)
            {
                Layer  subLayer  = layer.layers[index];
                string layerName = subLayer.name;           //Shop_Tab:Shop
                if (layerName.ToLower().Contains("_tab"))
                {
                    Tab tab = ImportTabLayer(subLayer, tabGroup.gameObject);
                    tab.group = tabGroup;
                }
                else
                {
                    ctrl.DrawLayer(subLayer, tabGroup.gameObject);
                }
            }
        }
        public void DrawLayer(Layer layer, GameObject parent)
        {
            UnityEngine.UI.Button button = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Button>(PSDImporterConst.ASSET_PATH_BUTTON, layer.name, parent);

            if (layer.layers != null)
            {
                for (int imageIndex = 0; imageIndex < layer.layers.Length; imageIndex++)
                {
                    PSImage image     = layer.layers[imageIndex].image;
                    string  lowerName = image.name.ToLower();
                    if (image.imageType != ImageType.Label && image.imageType != ImageType.Texture)
                    {
                        if (image.imageSource == ImageSource.Custom || image.imageSource == ImageSource.Common)
                        {
                            string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
                            Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;

                            if (image.name.ToLower().Contains("normal"))
                            {
                                button.image.sprite = sprite;
                                RectTransform rectTransform = button.GetComponent <RectTransform>();
                                rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
                                rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);

                                adjustButtonBG(image.imageType, button);
                            }
                            else if (image.name.ToLower().Contains("pressed"))
                            {
                                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                                UnityEngine.UI.SpriteState state = button.spriteState;
                                state.pressedSprite = sprite;
                                button.spriteState  = state;
                            }
                            else if (image.name.ToLower().Contains("disabled"))
                            {
                                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                                UnityEngine.UI.SpriteState state = button.spriteState;
                                state.disabledSprite = sprite;
                                button.spriteState   = state;
                            }
                            else if (image.name.ToLower().Contains("highlighted"))
                            {
                                button.transition = UnityEngine.UI.Selectable.Transition.SpriteSwap;
                                UnityEngine.UI.SpriteState state = button.spriteState;
                                state.highlightedSprite = sprite;
                                button.spriteState      = state;
                            }
                        }
                    }
                    else
                    {
                        //ctrl.DrawImage(image, button.gameObject);
                        ctrl.DrawLayer(layer.layers[imageIndex], button.gameObject);
                    }
                }
            }
        }
示例#3
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            UnityEngine.UI.Toggle toggle = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Toggle>(PSDImporterConst.ASSET_PATH_TOGGLE, layer.name, parent);

            if (layer.layers == null)
            {
                Debug.LogError("error! bad toggle layers.");
                return;
            }

            for (int index = 0; index < layer.layers.Length; index++)
            {
                Layer   subLayer = layer.layers[index];
                PSImage image    = subLayer.image;
                if (image != null)
                {
                    string lowerName = image.name.ToLower();
                    if (lowerName.Contains("_checkmark"))
                    {
                        ctrl.DrawImage(image, toggle.gameObject, toggle.graphic.gameObject);
                    }
                    else if (lowerName.Contains("_background"))
                    {
                        ctrl.DrawImage(image, toggle.gameObject, toggle.targetGraphic.gameObject);
                    }
                    else
                    {
                        ctrl.DrawImage(image, toggle.gameObject);
                    }
                }
                else
                {
                    ctrl.DrawLayer(subLayer, toggle.gameObject);
                }
            }
        }
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_SCROLLVIEW, layer.name, parent);

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

            UINode childNode = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_IMAGE, "Viewport", node);

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

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

            bool havebg = false;

            for (int i = 0; i < layer.images.Length; i++)
            {
                Image 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>(), parent.InitComponent <RectTransform>());
            }

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

            if (layer.arguments != null)
            {
                string type = layer.arguments[0].ToUpper();
                switch (type)
                {
                case "V":
                    scrollRect.vertical   = true;
                    scrollRect.horizontal = false;
                    break;

                case "H":
                    scrollRect.vertical   = false;
                    scrollRect.horizontal = true;
                    break;

                case "VH":
                case "HV":
                    scrollRect.vertical   = true;
                    scrollRect.horizontal = true;
                    break;

                default:
                    break;
                }
            }

            if (layer.layers != null)
            {
                for (int i = 0; i < layer.layers.Length; i++)
                {
                    Layer  child          = layer.layers[i];
                    string childLowerName = child.name;
                    UINode 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);
        }
示例#5
0
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode        node      = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_DROPDOWN, layer.name, parent);
            Dropdown      dropdown  = node.InitComponent <Dropdown>();
            ScrollRect    scrllRect = dropdown.template.GetComponent <ScrollRect>();
            RectTransform content   = scrllRect.content;
            Toggle        toggle    = content.GetComponentInChildren <Toggle>();

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

            childNode.transform.SetParent(PSDImportUtility.canvas.transform);
            childNode.anchoType = UINode.AnchoType.Down | UINode.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.Length; i++)
            {
                Image  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.size.height);
                }
                else if (lowerName.StartsWith("l1_"))
                {
                    PSDImportUtility.SetPictureOrLoadColor(image, dropdown.captionText);
                    float size;
                    if (float.TryParse(image.arguments[2], out size))
                    {
                        dropdown.captionText.fontSize = (int)size;
                    }
                    dropdown.captionText.text = image.arguments[3];
                }
                else if (lowerName.StartsWith("l2_"))
                {
                    PSDImportUtility.SetPictureOrLoadColor(image, dropdown.itemText);
                    float size;
                    if (float.TryParse(image.arguments[2], out size))
                    {
                        dropdown.itemText.fontSize = (int)size;
                    }
                    dropdown.itemText.text = image.arguments[3];
                }
                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.layers.Length; i++)
            {
                Layer  child     = layer.layers[i];
                string lowerName = child.name;
                if (lowerName.StartsWith("vb_"))
                {
                    UINode barNode = ctrl.DrawLayer(child, childNode);
                    scrllRect.verticalScrollbar           = barNode.InitComponent <Scrollbar>();
                    scrllRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHide;
                }
                else
                {
                    ctrl.DrawLayer(child, node);
                }
            }

            return(node);
        }