//using UnityEngine; //using System.Collections; //using UnityEditor; //using System.IO; //using System.Collections.Generic; /// < summary > /// 切割 /// //public static class ImageSlicer //{ // [MenuItem("Assets/ImageSlicer/Process to Sprites")] // static void ProcessToSprite() // { // Texture2D image = Selection.activeObject as Texture2D;//获取旋转的对象 // string rootPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(image));//获取路径名称 // string path = rootPath + "/" + image.name + ".PNG";//图片路径名称 // TextureImporter texImp = AssetImporter.GetAtPath(path) as TextureImporter;//获取图片入口 // AssetDatabase.CreateFolder(rootPath, image.name);//创建文件夹 // foreach (SpriteMetaData metaData in texImp.spritesheet)//遍历小图集 // { // Texture2D myimage = new Texture2D((int)metaData.rect.width, (int)metaData.rect.height); // abc_0: (x: 2.00, y: 400.00, width: 103.00, height: 112.00) // for (int y = (int)metaData.rect.y; y < metaData.rect.y + metaData.rect.height; y++)//Y轴像素 // { // for (int x = (int)metaData.rect.x; x < metaData.rect.x + metaData.rect.width; x++) // myimage.SetPixel(x - (int)metaData.rect.x, y - (int)metaData.rect.y, image.GetPixel(x, y)); // } // 转换纹理到EncodeToPNG兼容格式 // if (myimage.format != TextureFormat.ARGB32 && myimage.format != TextureFormat.RGB24) // { // Texture2D newTexture = new Texture2D(myimage.width, myimage.height); // newTexture.SetPixels(myimage.GetPixels(0), 0); // myimage = newTexture; // } // DeCompress(myimage); // var pngData = myimage.EncodeToPNG(); // AssetDatabase.CreateAsset(myimage, rootPath + "/" + image.name + "/" + metaData.name + ".PNG"); // File.WriteAllBytes(rootPath + "/" + image.name + "/" + metaData.name + ".PNG", pngData); // 刷新资源窗口界面 // AssetDatabase.Refresh(); // } // } // / // / // / // / // / < returns > // public static Texture2D DeCompress(Texture2D source) // { // RenderTexture renderTex = RenderTexture.GetTemporary( // source.width, // source.height, // 0, // RenderTextureFormat.Default, // RenderTextureReadWrite.Linear); // Graphics.Blit(source, renderTex); // RenderTexture previous = RenderTexture.active; // RenderTexture.active = renderTex; // Texture2D readableText = new Texture2D(source.width, source.height); // readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0); // readableText.Apply(); // RenderTexture.active = previous; // RenderTexture.ReleaseTemporary(renderTex); // return readableText; // } //}