mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
Fix for ArgumentException: Texture2D.SetPixels: texture uses an unsupported format
This commit is contained in:
parent
0a3b5dbb31
commit
12e424bee1
@ -206,13 +206,21 @@ namespace Spine.Unity.Editor {
|
|||||||
Texture2D texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);
|
Texture2D texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);
|
||||||
if (texture2D) {
|
if (texture2D) {
|
||||||
Color[] maxTextureSizePixels = texture2D.GetPixels();
|
Color[] maxTextureSizePixels = texture2D.GetPixels();
|
||||||
texture2D.SetPixels(maxTextureSizePixels);
|
|
||||||
|
|
||||||
var bytes = texture2D.EncodeToPNG();
|
// SetPixels works only for non-compressed textures using certain formats.
|
||||||
|
var nonCompressedTexture =
|
||||||
|
new Texture2D(texture2D.width, texture2D.height, TextureFormat.RGBA32, false);
|
||||||
|
|
||||||
|
nonCompressedTexture.SetPixels(maxTextureSizePixels);
|
||||||
|
|
||||||
|
var bytes = nonCompressedTexture.EncodeToPNG();
|
||||||
string targetPath = Application.dataPath + "/../" + texturePath;
|
string targetPath = Application.dataPath + "/../" + texturePath;
|
||||||
System.IO.File.WriteAllBytes(targetPath, bytes);
|
System.IO.File.WriteAllBytes(targetPath, bytes);
|
||||||
texture2D.Apply(updateMipmaps: true, makeNoLongerReadable: true);
|
|
||||||
EditorUtility.SetDirty(texture2D);
|
importer.isReadable = false;
|
||||||
|
importer.SaveAndReimport();
|
||||||
|
|
||||||
|
EditorUtility.SetDirty(nonCompressedTexture);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user