Beispiel #1
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null)
        {
            if (image.imageSource == ImageSource.Common || image.imageSource == ImageSource.Private)
            {
                Image pic;
                if (ownObj != null)
                {
                    pic = PSDImportUtility.AddMissingComponent <Image>(ownObj);
                }
                else
                {
                    pic = PSDImportUtility.LoadAndInstant <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);
                var    p      = PSDImportCtrl.Instance.GetFilePath(image);
                Sprite sprite = AssetDatabase.LoadAssetAtPath(p, typeof(Sprite)) as Sprite;

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

                pic.sprite = sprite;

                rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
                rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
            }
        }
Beispiel #2
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 = PSDImportUtility.AddMissingComponent <Image>(ownObj);
            }
            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 = PSDImportUtility.LoadAssetAtPath <Sprite>(image) 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 <Mirror>();

            if (image.imageType == ImageType.BottomHalfImage)
            {
                mirror.mirrorType = Mirror.MirrorType.Vertical;
            }
            else if (image.imageType == ImageType.LeftHalfImage)
            {
                mirror.mirrorType = Mirror.MirrorType.Horizontal;
            }
            else if (image.imageType == ImageType.QuarterImage)
            {
                mirror.mirrorType = Mirror.MirrorType.Quarter;
            }
            mirror.SetNativeSize();
        }
Beispiel #3
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null)
        {
            RawImage pic;

            if (ownObj != null)
            {
                pic = PSDImportUtility.AddMissingComponent <RawImage>(ownObj);
            }
            else
            {
                pic = PSDImportUtility.LoadAndInstant <RawImage>(PSDImporterConst.ASSET_PATH_RAWIMAGE, image.name, parent);
            }
            Texture2D texture = PSDImportUtility.LoadAssetAtPath <Texture2D>(image) 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);
        }
Beispiel #4
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj)
        {
            Image pic;

            if (ownObj != null)
            {
                pic = PSDImportUtility.AddMissingComponent <Image>(ownObj);
            }
            else
            {
                pic = PSDImportUtility.LoadAndInstant <Image>(PSDImporterConst.ASSET_PATH_IMAGE, image.name, parent);
            }

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

            PSDImportUtility.SetAnchorMiddleCenter(rectTransform);
            //var p = PSDImportCtrl.Instance.GetFilePath(image);
            //var imp = AssetImporter.GetAtPath(p) as TextureImporter;
            //if (!PSDImportCtrl.Instance.IsSetBorder(imp))
            //{
            //    PSDImportCtrl.Instance.SetSpriteBorder(imp, image.arguments);
            //    AssetDatabase.WriteImportSettingsIfDirty(p);
            //    AssetDatabase.ImportAsset(p);
            //}
            //else
            //{
            //    Debug.Log("已设置九宫格:"+p);
            //}
            Sprite sprite = PSDImportUtility.LoadAssetAtPath <Sprite>(image) as Sprite;

            pic.sprite = sprite;
            pic.type   = 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);
        }
Beispiel #5
0
        public void DrawImage(PSImage image, GameObject parent, GameObject ownObj = null)
        {
            Text myText;

            if (ownObj != null)
            {
                myText = PSDImportUtility.AddMissingComponent <Text>(ownObj);
            }
            else
            {
                myText = PSDImportUtility.LoadAndInstant <Text>(PSDImporterConst.ASSET_PATH_TEXT, image.name, parent);
            }
            RectTransform rectTransform = myText.GetComponent <RectTransform>();

            PSDImportUtility.SetAnchorMiddleCenter(rectTransform);
            Debug.Log("Label Color : " + image.arguments[0]);
            Debug.Log("fontSize : " + image.arguments[2]);
            Color color;

            if (ColorUtility.TryParseHtmlString(("#" + image.arguments[0]), out color))
            {
                myText.color = color;
            }
            else
            {
                Debug.Log(image.arguments[0]);
            }

            float size;

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

            myText.text = image.arguments[3];

            //设置字体,注意unity中的字体名需要和导出的xml中的一致
            string fontFolder;

            if (image.arguments[1].ToLower().Contains("static"))
            {
                fontFolder = PSDImporterConst.FONT_STATIC_FOLDER;
            }
            else
            {
                fontFolder = PSDImporterConst.FONT_FOLDER;
            }
            string fontFullName = fontFolder + image.arguments[1] + PSDImporterConst.FONT_SUFIX;

            Debug.Log("font name ; " + fontFullName);
            var font = AssetDatabase.LoadAssetAtPath(fontFullName, typeof(Font)) as Font;

            if (font == null)
            {
                Debug.LogWarning("Load font failed : " + fontFullName);
            }
            else
            {
                myText.font = font;
            }
            //ps的size在unity里面太小,文本会显示不出来,暂时选择溢出
            myText.verticalOverflow   = VerticalWrapMode.Overflow;
            myText.horizontalOverflow = HorizontalWrapMode.Overflow;
            //设置对齐
            if (image.arguments.Length >= 5)
            {
                myText.alignment = ParseAlignmentPS2UGUI(image.arguments[4]);
            }

            rectTransform.sizeDelta        = new Vector2(image.size.width, image.size.height);
            rectTransform.anchoredPosition = new Vector2(image.position.x, image.position.y);
            myText.gameObject.name         = "Text";
        }