Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }