Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 3b4ea31

Browse files
committed
Fix Texture2D saver in Mono and for non-readable textures
1 parent ad7b05f commit 3b4ea31

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/ExplorerCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace UnityExplorer
1616
public class ExplorerCore
1717
{
1818
public const string NAME = "UnityExplorer";
19-
public const string VERSION = "3.1.2";
19+
public const string VERSION = "3.1.3";
2020
public const string AUTHOR = "Sinai";
2121
public const string GUID = "com.sinai.unityexplorer";
2222
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer";

src/Helpers/Texture2DHelpers.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public static class Texture2DHelpers
1515
private static MethodInfo EncodeToPNGMethod => m_encodeToPNGMethod ?? GetEncodeToPNGMethod();
1616
private static MethodInfo m_encodeToPNGMethod;
1717

18+
public static byte[] EncodeToPNGSafe(this Texture2D tex)
19+
{
20+
var method = EncodeToPNGMethod;
21+
22+
if (method.IsStatic)
23+
return (byte[])method.Invoke(null, new object[] { tex });
24+
else
25+
return (byte[])method.Invoke(tex, new object[0]);
26+
}
27+
1828
private static MethodInfo GetEncodeToPNGMethod()
1929
{
2030
if (ReflectionHelpers.GetTypeByName("UnityEngine.ImageConversion") is Type imageConversion)

src/Inspectors/Reflection/InstanceInspector.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,14 @@ internal void ConstructTextureViewerArea(GameObject parent)
272272
if (File.Exists(path))
273273
File.Delete(path);
274274

275-
var data = tex.EncodeToPNG();
275+
if (!tex.IsReadable())
276+
tex = Texture2DHelpers.ForceReadTexture(tex);
277+
#if CPP
278+
byte[] data = tex.EncodeToPNG();
279+
#else
280+
byte[] data = tex.EncodeToPNGSafe();
281+
#endif
282+
276283
File.WriteAllBytes(path, data);
277284
}
278285
});

0 commit comments

Comments
 (0)