This repository was archived by the owner on May 9, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Expand file tree Collapse file tree 3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ namespace UnityExplorer
16
16
public class ExplorerCore
17
17
{
18
18
public const string NAME = "UnityExplorer" ;
19
- public const string VERSION = "3.1.2 " ;
19
+ public const string VERSION = "3.1.3 " ;
20
20
public const string AUTHOR = "Sinai" ;
21
21
public const string GUID = "com.sinai.unityexplorer" ;
22
22
public const string EXPLORER_FOLDER = @"Mods\UnityExplorer" ;
Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ public static class Texture2DHelpers
15
15
private static MethodInfo EncodeToPNGMethod => m_encodeToPNGMethod ?? GetEncodeToPNGMethod ( ) ;
16
16
private static MethodInfo m_encodeToPNGMethod ;
17
17
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
+
18
28
private static MethodInfo GetEncodeToPNGMethod ( )
19
29
{
20
30
if ( ReflectionHelpers . GetTypeByName ( "UnityEngine.ImageConversion" ) is Type imageConversion )
Original file line number Diff line number Diff line change @@ -272,7 +272,14 @@ internal void ConstructTextureViewerArea(GameObject parent)
272
272
if ( File . Exists ( path ) )
273
273
File . Delete ( path ) ;
274
274
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
+
276
283
File . WriteAllBytes ( path , data ) ;
277
284
}
278
285
} ) ;
You can’t perform that action at this time.
0 commit comments