Пример #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);
                }
            }
        }
Пример #2
0
        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)
            {
                //for (int imageIndex = 0; imageIndex < layer.images.Length; imageIndex++)
                //{
                PSImage image = layer.image;
                ctrl.DrawImage(image, obj.gameObject);
                //}
            }

            ctrl.DrawLayers(layer.layers, obj.gameObject);
            //obj.transform.SetParent(parent.transform, false); //parent.transform;
        }
Пример #3
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null)
        {
            UnityEngine.UI.RawImage pic;
            if (ownObj != null)
            {
                pic = ownObj.AddMissingComponent <UnityEngine.UI.RawImage>();
            }
            else
            {
                pic = PSDImportUtility.LoadAndInstant <UnityEngine.UI.RawImage>(PSDImporterConst.ASSET_PATH_RAWIMAGE, image.name, parent);
            }

//             string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
//             Texture2D texture = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D)) as Texture2D;
//             if (texture == null)
//             {
//                 Debug.Log("loading asset at path: " + PSDImportUtility.baseDirectory + image.name);
//             }
            Texture2D texture = image.LoadAssetAtPath <Texture2D>() as Texture2D;

            pic.texture = texture as Texture;
            RectTransform rectTransform = pic.GetComponent <RectTransform>();

            PSDImportUtility.SetAnchorMiddleCenter(rectTransform);
            rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
            rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
        }
Пример #4
0
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_BUTTON, layer.name, parent);

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

            if (layer.images != null)
            {
                for (int imageIndex = 0; imageIndex < layer.images.Length; imageIndex++)
                {
                    Image  image     = layer.images[imageIndex];
                    string lowerName = image.name.ToLower();
                    if (image.imageType == ImageType.Image && lowerName.StartsWith("n_") || lowerName.StartsWith("p_") || lowerName.StartsWith("d_") || lowerName.StartsWith("h_"))
                    {
                        if (image.arguments == null || image.arguments.Length == 0)
                        {
                            SetSpriteSwipe(image, button);
                        }
                        else
                        {
                            SetColorSwipe(image, button);
                        }
                    }
                    else
                    {
                        ctrl.DrawImage(image, node);
                    }
                }
            }
            return(node);
        }
Пример #5
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.GetComponent <UnityEngine.UI.Image>();

            ctrl.DrawLayers(layer.layers, node);//子节点

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

                if (image.name.ToLower().StartsWith("b_"))
                {
                    PSDImportUtility.SetPictureOrLoadColor(image, panel);
                    PSDImportUtility.SetRectTransform(image, panel.GetComponent <RectTransform>());
                    panel.name = layer.name;
                }
                else
                {
                    ctrl.DrawImage(image, node);
                }
            }
            return(node);
        }
Пример #6
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            //UnityEngine.UI.Image temp = AssetDatabase.LoadAssetAtPath(PSDImporterConst.PREFAB_PATH_IMAGE, typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;
            UnityEngine.UI.Image panel = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, layer.name, parent);//GameObject.Instantiate(temp) as UnityEngine.UI.Image;

            panel.name = layer.name;

            ctrl.DrawLayers(layer.layers, panel.gameObject);//子节点

            //for (int i = 0; i < layer.images.Length; i++)
            //{
            PSImage image = layer.image;

            if (image.name.ToLower().Contains("background"))
            {
                string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
                Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
                panel.sprite = sprite;

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

                //panel.transform.SetParent(parent.transform, false); //parent = parent.transform;
            }
            else
            {
                ctrl.DrawImage(image, panel.gameObject);
            }
            //}
        }
Пример #7
0
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_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.Length; imageIndex++)
                {
                    Image  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);
        }
        public void DrawLayer(Layer layer, GameObject parent)
        {
            RectTransform obj           = PSDImportUtility.LoadAndInstant <RectTransform>(PSDImporterConst.ASSET_PATH_LAYOUTELEMENT, layer.name, parent);
            RectTransform rectTransform = parent.GetComponent <RectTransform>();

            obj.sizeDelta        = new Vector2(layer.size.width, layer.size.height);
            obj.anchoredPosition = new Vector2(layer.position.x, layer.position.y);

            var le = obj.GetComponent <LayoutElement>();

            le.preferredWidth  = layer.size.width;
            le.preferredHeight = layer.size.height;

            if (layer.image != null)
            {
                //for (int imageIndex = 0; imageIndex < layer.layers.Length; imageIndex++)
                //{
                PSImage image = layer.image;
                ctrl.DrawImage(image, obj.gameObject);
                //}
            }

            ctrl.DrawLayers(layer.layers, obj.gameObject);
            //obj.transform.SetParent(parent.transform, false); //parent.transform;
        }
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj)
        {
            //UnityEngine.UI.Image pic = AssetDatabase.LoadAssetAtPath(PSDImporterConst.PREFAB_PATH_IMAGE, typeof(UnityEngine.UI.Image)) as UnityEngine.UI.Image;
            //string commonImagePath = PSDImporterConst.Globle_BASE_FOLDER + image.name.Replace(".", "/") + PSDImporterConst.PNG_SUFFIX;
            //Debug.Log("==  CommonImagePath  ====" + commonImagePath);
            //Sprite sprite = AssetDatabase.LoadAssetAtPath(commonImagePath, typeof(Sprite)) as Sprite;

            UnityEngine.UI.Image pic = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, parent);

            string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
            Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;

            if (sprite == null)
            {
                Debug.Log("loading asset at path: " + PSDImportUtility.baseDirectory + image.name);
            }

            //string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
            //Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
            //UnityEngine.UI.Image myImage = GameObject.Instantiate(pic) as UnityEngine.UI.Image;

            pic.sprite = sprite;
            pic.type   = UnityEngine.UI.Image.Type.Sliced;

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

            rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
            rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
        }
Пример #10
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null)
        {
            RectTransform halfRectTrans = parent.GetComponent <RectTransform>();

            //2017.1.20注:因为已经修改为layer会创建gameobject,所以不再需要加载预设,直接在parent下组装即可
            //创建一个节点存放两张半图
            //var halfRectTrans = PSDImportUtility.LoadAndInstant<RectTransform>(PSDImporterConst.ASSET_PATH_HALFIMAGE, image.name, parent);
            PSDImportUtility.SetAnchorMiddleCenter(halfRectTrans);
            halfRectTrans.sizeDelta        = new Vector2(image.size.width, image.size.height);
            halfRectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y);

            UnityEngine.UI.Image leftOrUpSprite   = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, halfRectTrans.gameObject);
            UnityEngine.UI.Image rightOrLowSprite = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, halfRectTrans.gameObject);

            string assetPath = "";

            if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom)
            {
                assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
            }
            else
            {
                assetPath = PSDImporterConst.Globle_BASE_FOLDER + image.name.Replace(".", "/") + PSDImporterConst.PNG_SUFFIX;
            }

            Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;

            if (sprite == null)
            {
                Debug.Log("loading asset at path: " + assetPath);
            }

            leftOrUpSprite.sprite   = sprite;
            rightOrLowSprite.sprite = sprite;
            RectTransform lOrURectTrans = leftOrUpSprite.GetComponent <RectTransform>();
            RectTransform rOrLRectTrans = rightOrLowSprite.GetComponent <RectTransform>();

            Vector2 size;

            if (image.imageType == ImageType.UpHalfImage)
            {
                size = new Vector2(image.size.width, image.size.height / 2f);
                lOrURectTrans.sizeDelta        = size;
                lOrURectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y + image.size.height / 4f);//还未设置父节点,要用绝对坐标

                rOrLRectTrans.sizeDelta        = size;
                rOrLRectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y - image.size.height / 4f);
                rOrLRectTrans.localEulerAngles = new Vector3(180, 0, 0);
            }
            else
            {
                size = new Vector2(image.size.width / 2f, image.size.height);
                lOrURectTrans.sizeDelta        = size;
                lOrURectTrans.anchoredPosition = new Vector2(image.position.x - image.size.width / 4f, image.position.y);
                rOrLRectTrans.sizeDelta        = size;
                rOrLRectTrans.anchoredPosition = new Vector2(image.position.x + image.size.width / 4f, image.position.y);
                rOrLRectTrans.localEulerAngles = new Vector3(0, 180, 0);
            }
        }
Пример #11
0
 public void BeginSetAnchers(UINode node)
 {
     foreach (var item in node.childs)
     {
         BeginSetAnchers(item);
         PSDImportUtility.SetAnchorByNode(item);
     }
 }
Пример #12
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null)
        {
            RectTransform halfRectTrans = parent.GetComponent <RectTransform>();

            PSDImportUtility.SetAnchorMiddleCenter(halfRectTrans);
            halfRectTrans.sizeDelta        = new Vector2(image.size.width, image.size.height);
            halfRectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y);

            UnityEngine.UI.Image leftOrUpSprite;
            if (ownObj != null)
            {
                leftOrUpSprite = ownObj.AddMissingComponent <UnityEngine.UI.Image>();
            }
            else
            {
                leftOrUpSprite = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, halfRectTrans.gameObject);
            }

            //string assetPath = "";
            //if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom)
            //{
            //    assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
            //}
            //else
            //{
            //    assetPath = PSDImporterConst.Globle_BASE_FOLDER + image.name.Replace(".", "/") + PSDImporterConst.PNG_SUFFIX;
            //}

            //Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;
            Sprite sprite = image.LoadAssetAtPath <Sprite>() as Sprite;

//             if (sprite == null)
//             {
//                 Debug.Log("loading asset at path: " + assetPath);
//             }

            leftOrUpSprite.sprite = sprite;
            RectTransform lOrURectTrans = leftOrUpSprite.GetComponent <RectTransform>();

            lOrURectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y);

            //添加镜像组件
            var mirror = lOrURectTrans.gameObject.AddComponent <UGUI.Effects.Mirror>();

            if (image.imageType == ImageType.BottomHalfImage)
            {
                mirror.mirrorType = UGUI.Effects.Mirror.MirrorType.Vertical;
            }
            else if (image.imageType == ImageType.LeftHalfImage)
            {
                mirror.mirrorType = UGUI.Effects.Mirror.MirrorType.Horizontal;
            }
            else if (image.imageType == ImageType.QuarterImage)
            {
                mirror.mirrorType = UGUI.Effects.Mirror.MirrorType.Quarter;
            }
            mirror.SetNativeSize();
        }
Пример #13
0
        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);
                    }
                }
            }
        }
Пример #14
0
        private UINode DrawRawImage(Image image, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_RawIMAGE, image.name, parent);

            UnityEngine.UI.RawImage pic = node.GetComponent <UnityEngine.UI.RawImage>();
            PSDImportUtility.SetPictureOrLoadColor(image, pic);
            PSDImportUtility.SetRectTransform(image, pic.GetComponent <RectTransform>());
            return(node);
        }
Пример #15
0
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode    node      = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_SCROLLBAR, layer.name, parent);
            Scrollbar scrollBar = node.InitComponent <Scrollbar>();

            string type = layer.arguments[0].ToUpper();

            switch (type)
            {
            case "R":
                scrollBar.direction = Scrollbar.Direction.RightToLeft;
                break;

            case "L":
                scrollBar.direction = Scrollbar.Direction.LeftToRight;
                break;

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

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

            default:
                break;
            }

            for (int i = 0; i < layer.images.Length; i++)
            {
                Image  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);
        }
Пример #16
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null)
        {
            if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom)
            {
                UnityEngine.UI.Image pic;
                if (ownObj != null)
                {
                    pic = ownObj.AddMissingComponent <UnityEngine.UI.Image>();
                }
                else
                {
                    pic = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, parent);
                }

                RectTransform rectTransform = pic.GetComponent <RectTransform>();
                rectTransform.offsetMin = new Vector2(0.5f, 0.5f);
                rectTransform.offsetMax = new Vector2(0.5f, 0.5f);
                rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
                rectTransform.anchorMax = new Vector2(0.5f, 0.5f);

                string assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
                Sprite sprite    = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;

                if (sprite == null)
                {
                    Debug.Log("loading asset at path: " + PSDImportUtility.baseDirectory + image.name);
                }

                pic.sprite = sprite;

                rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
                rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
            }
            else if (image.imageSource == ImageSource.Global)
            {
                UnityEngine.UI.Image pic;
                if (ownObj != null)
                {
                    pic = ownObj.AddMissingComponent <UnityEngine.UI.Image>();
                }
                else
                {
                    pic = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, parent);
                }

                RectTransform rectTransform = pic.GetComponent <RectTransform>();
                rectTransform.offsetMin = new Vector2(0.5f, 0.5f);
                rectTransform.offsetMax = new Vector2(0.5f, 0.5f);
                rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
                rectTransform.anchorMax = new Vector2(0.5f, 0.5f);

                SetGlobalImage(pic, image);
                pic.name = image.name;
            }
        }
Пример #17
0
        private Tab ImportTabLayer(Layer layer, GameObject parent)
        {
            string tabName = layer.name.Substring(0, layer.name.IndexOf("_Tab"));
            string tag     = layer.name.LastIndexOf(':') == -1 ? tabName : layer.name.Substring(layer.name.LastIndexOf(':') + 1);
            //Debug.LogWarning("tab name = " + tabName + "  tab tag = " + tag);

            Tab tab = PSDImportUtility.LoadAndInstant <Tab>(PSDImporterConst.ASSET_PATH_TAB, tabName, parent);

            tab.tag = tag;

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

            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("_tabsel"))
                    {
                        ctrl.DrawImage(image, tab.gameObject, tab.graphic.gameObject);
                    }
                    else if (lowerName.Contains("_tabunsel"))
                    {
                        ctrl.DrawImage(image, tab.gameObject, tab.targetGraphic.gameObject);
                    }
                    else
                    {
                        ctrl.DrawImage(image, tab.gameObject);
                    }
                }
                else
                {
                    if (subLayer.name.ToLower().Contains("_page"))
                    {
                        string name = subLayer.name.Substring(0, subLayer.name.Length - 5);
                        tab.page.gameObject.name = name;
                        ctrl.DrawLayers(subLayer.layers, tab.page.gameObject);      //跳过page层,只绘制子
                    }
                    else
                    {
                        ctrl.DrawLayer(subLayer, tab.gameObject);
                    }
                }
            }

            return(tab);
        }
Пример #18
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null)
        {
            RectTransform halfRectTrans = parent.GetComponent <RectTransform>();

            //2017.1.20注:因为已经修改为layer会创建gameobject,所以不再需要加载预设,直接在parent下组装即可
            //创建一个节点存放两张半图
            //var halfRectTrans = PSDImportUtility.LoadAndInstant<RectTransform>(PSDImporterConst.ASSET_PATH_HALFIMAGE, image.name, parent);
            PSDImportUtility.SetAnchorMiddleCenter(halfRectTrans);
            halfRectTrans.sizeDelta        = new Vector2(image.size.width, image.size.height);
            halfRectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y);

            UnityEngine.UI.Image leftOrUpSprite = PSDImportUtility.LoadAndInstant <UnityEngine.UI.Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, halfRectTrans.gameObject);

            string assetPath = "";

            if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Custom)
            {
                assetPath = PSDImportUtility.baseDirectory + image.name + PSDImporterConst.PNG_SUFFIX;
            }
            else
            {
                assetPath = PSDImporterConst.Globle_BASE_FOLDER + image.name.Replace(".", "/") + PSDImporterConst.PNG_SUFFIX;
            }

            Sprite sprite = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Sprite)) as Sprite;

            if (sprite == null)
            {
                Debug.Log("loading asset at path: " + assetPath);
            }

            leftOrUpSprite.sprite = sprite;
            RectTransform lOrURectTrans = leftOrUpSprite.GetComponent <RectTransform>();

            lOrURectTrans.anchoredPosition = new Vector2(image.position.x, image.position.y);

            //添加镜像组件
            var mirror = lOrURectTrans.gameObject.AddComponent <UGUI.Effects.Mirror>();

            if (image.imageType == ImageType.BottomHalfImage)
            {
                mirror.mirrorType = UGUI.Effects.Mirror.MirrorType.Vertical;
            }
            else if (image.imageType == ImageType.LeftHalfImage)
            {
                mirror.mirrorType = UGUI.Effects.Mirror.MirrorType.Horizontal;
            }
            else if (image.imageType == ImageType.QuarterImage)
            {
                mirror.mirrorType = UGUI.Effects.Mirror.MirrorType.Quarter;
            }
            mirror.SetNativeSize();
        }
Пример #19
0
        public void BeginDrawUILayers()
        {
            UINode        empty = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_EMPTY, PSDImportUtility.baseFilename, PSDImportUtility.uinode);
            RectTransform rt    = empty.InitComponent <RectTransform>();

            rt.sizeDelta = new Vector2(psdUI.psdSize.width, psdUI.psdSize.height);
            for (int layerIndex = 0; layerIndex < psdUI.layers.Length; layerIndex++)
            {
                DrawLayer(psdUI.layers[layerIndex], empty);
            }
            AssetDatabase.Refresh();
        }
Пример #20
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            //UnityEngine.UI.ScrollRect temp = AssetDatabase.LoadAssetAtPath(PSDImporterConst.PREFAB_PATH_SCROLLVIEW, typeof(UnityEngine.UI.ScrollRect)) as UnityEngine.UI.ScrollRect;
            UnityEngine.UI.ScrollRect scrollRect = PSDImportUtility.LoadAndInstant <UnityEngine.UI.ScrollRect>(PSDImporterConst.ASSET_PATH_SCROLLVIEW, layer.name, parent);
            //scrollRect.transform.SetParent(parent.transform, false); //parent = parent.transform;


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

            rectTransform.sizeDelta        = new Vector2(layer.size.width, layer.size.height);
            rectTransform.anchoredPosition = new Vector2(layer.position.x, layer.position.y);

            if (layer.layers != null)
            {
                string type = layer.arguments[0].ToUpper();
                switch (type)
                {
                case "V":
                    //scrollRect.vertical = true;
                    //scrollRect.horizontal = false;
                    if (layer.arguments.Length > 4)
                    {
                        BuildGridScrollView(scrollRect, layer, parent, true);
                        return;
                    }
                    else
                    {
                        BuildVerticalScrollView(scrollRect, layer);
                    }
                    break;

                case "H":
                    //scrollRect.vertical = false;
                    //scrollRect.horizontal = true;
                    if (layer.arguments.Length > 4)
                    {
                        BuildGridScrollView(scrollRect, layer, parent, false);
                        return;
                    }
                    else
                    {
                        BuildHorizonScrollView(scrollRect, layer);
                    }
                    break;

                default:
                    break;
                }

                ctrl.DrawLayers(layer.layers, scrollRect.content.gameObject);
            }
        }
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_INPUTFIELD, layer.name, parent);

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

            if (layer.images != null)
            {
                for (int imageIndex = 0; imageIndex < layer.images.Length; imageIndex++)
                {
                    Image  image     = layer.images[imageIndex];
                    string lowerName = image.name.ToLower();

                    if (image.imageType == ImageType.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, inputfield.textComponent);

                            int size;
                            if (int.TryParse(image.arguments[2], out size))
                            {
                                text.fontSize = size;
                            }
                        }
                        else if (lowerName.StartsWith("p_"))
                        {
                            UnityEngine.UI.Text text = (UnityEngine.UI.Text)inputfield.placeholder;//.transform.Find("Placeholder").GetComponent<UnityEngine.UI.Text>();
                            PSDImportUtility.SetPictureOrLoadColor(image, inputfield.textComponent);

                            int size;
                            if (int.TryParse(image.arguments[2], out size))
                            {
                                text.fontSize = size;
                            }
                        }
                    }
                    else
                    {
                        if (lowerName.StartsWith("b_"))
                        {
                            PSDImportUtility.SetPictureOrLoadColor(image, inputfield.image);
                            PSDImportUtility.SetRectTransform(image, inputfield.GetComponent <RectTransform>());
                        }
                    }
                }
            }
            return(node);
        }
Пример #22
0
        public void BeginDrawUILayers()
        {
            RectTransform obj = PSDImportUtility.LoadAndInstant <RectTransform>(PSDImporterConst.ASSET_PATH_EMPTY, PSDImportUtility.baseFilename, PSDImportUtility.canvas.gameObject);

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

            for (int layerIndex = 0; layerIndex < psdUI.layers.Length; layerIndex++)
            {
                DrawLayer(psdUI.layers[layerIndex], obj.gameObject);
            }
            AssetDatabase.Refresh();
        }
Пример #23
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);
                }
                //}
            }
        }
Пример #24
0
        private void InitDataAndPath(string xmlFilePath)
        {
            psdUI = (PSDUI)PSDImportUtility.DeserializeXml(xmlFilePath, typeof(PSDUI));
            Debug.Log(psdUI.psdSize.width + "=====psdSize======" + psdUI.psdSize.height);
            if (psdUI == null)
            {
                Debug.Log("The file " + xmlFilePath + " wasn't able to generate a PSDUI.");
                return;
            }

            if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo() == false)
            {
                return;
            }

            PSDImportUtility.baseFilename  = Path.GetFileNameWithoutExtension(xmlFilePath);
            PSDImportUtility.baseDirectory = "Assets/" + Path.GetDirectoryName(xmlFilePath.Remove(0, Application.dataPath.Length + 1)) + "/";
        }
Пример #25
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);
        }
Пример #26
0
        public void DrawLayer(Layer layer, GameObject parent)
        {
            UnityEngine.UI.GridLayoutGroup gridLayoutGroup = PSDImportUtility.LoadAndInstant <UnityEngine.UI.GridLayoutGroup>(PSDImporterConst.ASSET_PATH_GRID, layer.name, parent);

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

            rectTransform.sizeDelta        = new Vector2(layer.size.width, layer.size.height);
            rectTransform.anchoredPosition = new Vector2(layer.position.x, layer.position.y);

            gridLayoutGroup.padding = new RectOffset();

            float width, height;

            if (float.TryParse(layer.arguments[2], out width) && float.TryParse(layer.arguments[3], out height))
            {
                gridLayoutGroup.cellSize = new Vector2(width, height);
            }
            gridLayoutGroup.spacing = new Vector2(System.Convert.ToInt32(layer.arguments[4]), System.Convert.ToInt32(layer.arguments[5]));

            ctrl.DrawLayers(layer.layers, gridLayoutGroup.gameObject);
        }
Пример #27
0
        static public void ImportHogSceneMenuItem()
        {
            string startPath = null;

            if (Selection.activeObject != null)
            {
                startPath = AssetDatabase.GetAssetPath(Selection.activeObject);
            }
            if (startPath != null && startPath.EndsWith("xml"))
            {
                PSDImportCtrl import = new PSDUIImporter.PSDImportCtrl(startPath);
                import.BeginDrawUILayers();
                import.BeginSetUIParents(PSDImportUtility.uinode);
                import.BeginSetAnchers(PSDImportUtility.uinode.childs[0]);
                //最外层的要单独处理
                var rt = PSDImportUtility.uinode.childs[0].GetComponent <RectTransform>();
                PSDImportUtility.SetCustomAnchor(rt, rt);
                import.BeginReprocess(PSDImportUtility.uinode.childs[0]);//后处理
            }

            GC.Collect();
        }
Пример #28
0
        public UINode DrawImage(Image image, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_TEXT, image.name, parent);

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

            float size;

            if (float.TryParse(image.arguments[2], out size))
            {
                myText.fontSize = (int)size;
            }

            myText.text = image.arguments[3];

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

            rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
            rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
            return(node);
        }
Пример #29
0
        public UINode DrawLayer(Layer layer, UINode parent)
        {
            UINode node = PSDImportUtility.InstantiateItem(PSDImporterConst.PREFAB_PATH_GROUP, layer.name, parent);

            UnityEngine.UI.LayoutGroup group = null;
            string type = layer.arguments[0].ToLower();
            float  span = 0;

            float.TryParse(layer.arguments[1], out span);
            switch (type)
            {
            case "v":
                group = node.AddComponent <UnityEngine.UI.VerticalLayoutGroup>();
                group.childAlignment = TextAnchor.UpperLeft;
                ((UnityEngine.UI.VerticalLayoutGroup)group).spacing = span;
                break;

            case "h":
                group = node.AddComponent <UnityEngine.UI.HorizontalLayoutGroup>();
                group.childAlignment = TextAnchor.UpperLeft;
                ((UnityEngine.UI.HorizontalLayoutGroup)group).spacing = span;
                break;
            }

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

            UINode[] nodes = pSDImportCtrl.DrawImages(layer.images, node);
            foreach (var item in nodes)
            {
                item.anchoType = UINode.AnchoType.Left | UINode.AnchoType.Up;
            }
            nodes = pSDImportCtrl.DrawLayers(layer.layers, node);
            foreach (var item in nodes)
            {
                item.anchoType = UINode.AnchoType.Left | UINode.AnchoType.Up;
            }
            return(node);
        }
Пример #30
0
        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);
        }