示例#1
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            //UnityEngine.UI.Toggle temp = AssetDatabase.LoadAssetAtPath(PSDImporterConst.PREFAB_PATH_TOGGLE, typeof(UnityEngine.UI.Toggle)) as UnityEngine.UI.Toggle;
            UnityEngine.UI.Toggle toggle = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Toggle>(PSDImporterConst.ASSET_PATH_TOGGLE, layer.name, parent);// GameObject.Instantiate(temp) as UnityEngine.UI.Toggle;

            if (layer.image != null)
            {
                //for (int imageIndex = 0; imageIndex < layer.images.Length; imageIndex++)
                //{
                PSImage image = layer.image;

                if (image.name.ToLower().Contains("background"))
                {
                    if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom)
                    {
                        string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
                        Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
                        toggle.image.sprite = sprite;

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

                        //rectTransform.SetParent(parent.transform, true);

                        //PosLoader posloader = toggle.gameObject.AddComponent<PosLoader>();
                        //posloader.worldPos = rectTransform.position;
                    }
                }
                else if (image.name.ToLower().Contains("mask"))
                {
                    if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom)
                    {
                        string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
                        Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
                        toggle.graphic.GetComponent <UnityEngine.UI.Image>().sprite = sprite;
                    }
                }
                else
                {
                    ctrl.DrawImage(image, toggle.graphic.gameObject);
                }
                //}
            }
        }
示例#2
0
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode        node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_EMPTY, layer.name, parent);
            RectTransform obj  = node.GetComponent <RectTransform>();

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

            if (layer.images != null)
            {
                for (int imageIndex = 0; imageIndex < layer.images.Length; imageIndex++)
                {
                    Image image = layer.images[imageIndex];
                    ctrl.DrawImage(image, node);
                }
            }

            ctrl.DrawLayers(layer.layers, node);
            return(node);
        }
        public void DrawLayer(Layer layer, GameObject parent)
        {
            RectTransform obj = PSDImportUtility.LoadAndInstant <RectTransform>(PSDImporterConst.ASSET_PATH_EMPTY, layer.name, parent);

            obj.offsetMin = Vector2.zero;
            obj.offsetMax = Vector2.zero;
            obj.anchorMin = Vector2.zero;
            obj.anchorMax = Vector2.one;

            RectTransform rectTransform = parent.GetComponent <RectTransform>();

            obj.sizeDelta        = rectTransform.sizeDelta;
            obj.anchoredPosition = rectTransform.anchoredPosition;

            if (layer.image != null)
            {
                PSImage image = layer.image;
                //ctrl.DrawImage(image, obj.gameObject);
                ctrl.DrawImage(image, parent, obj.gameObject);
            }

            ctrl.DrawLayers(layer.layers, obj.gameObject);
        }
示例#4
0
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_IMAGE, layer.name, parent);//GameObject.Instantiate(temp) as UnityEngine.UI.Image;

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

            ctrl.DrawLayers(layer.layers, node);//子节点
            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;
                    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>(), parent.InitComponent <RectTransform>());
                Color color;
                if (ColorUtility.TryParseHtmlString("#FFFFFF01", out color))
                {
                    panel.GetComponent <UnityEngine.UI.Image>().color = color;
                }
                panel.name = layer.name;
            }
            return(node);
        }
        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);
        }
示例#6
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);
        }