static void SaveAsPng(bool sRGB)
        {
            var texture = Selection.activeObject as Texture2D;
            var path    = SaveDialog(AssetsPath.FromAsset(texture));

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            File.WriteAllBytes(path, texture.EncodeToPNG());
            Debug.Log($"save: {path}");

            var assetsPath = AssetsPath.FromFullpath(path);

            EditorApplication.delayCall += () =>
            {
                assetsPath.ImportAsset();
                var importer = assetsPath.GetImporter <TextureImporter>();
                if (importer == null)
                {
                    Debug.LogWarningFormat("fail to get TextureImporter: {0}", assetsPath);
                }
                importer.sRGBTexture = sRGB;
                importer.SaveAndReimport();
                Debug.Log($"sRGB: {sRGB}");
            };
        }
예제 #2
0
        static void SaveAsPng(bool sRGB)
        {
            var texture = Selection.activeObject as Texture2D;
            var path    = SaveDialog(AssetsPath.FromAsset(texture));

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var(tex, mime) = new EditorTextureSerializer().ExportBytesWithMime(texture, sRGB ? ColorSpace.sRGB : ColorSpace.Linear);

            File.WriteAllBytes(path, tex);
            Debug.Log($"save: {path}");

            var assetsPath = AssetsPath.FromFullpath(path);

            EditorApplication.delayCall += () =>
            {
                assetsPath.ImportAsset();
                var importer = assetsPath.GetImporter <TextureImporter>();
                if (importer == null)
                {
                    Debug.LogWarningFormat("fail to get TextureImporter: {0}", assetsPath);
                }
                importer.sRGBTexture = sRGB;
                importer.SaveAndReimport();
                Debug.Log($"sRGB: {sRGB}");
            };
        }