@@ -32,26 +32,42 @@ static class StreamExtensions
32
32
33
33
static StreamExtensions ( )
34
34
{
35
- var t = typeof ( Texture2D ) . Assembly . GetType ( "UnityEngine.ImageConversion" , false , false ) ;
36
- if ( t != null )
35
+ // 5.6
36
+ // looking for Texture2D.LoadImage(byte[] data)
37
+ loadImage = typeof ( Texture2D ) . GetMethods ( ) . FirstOrDefault ( x => x . Name == "LoadImage" && x . GetParameters ( ) . Length == 1 ) ;
38
+ if ( loadImage != null )
37
39
{
38
- // looking for ImageConversion.LoadImage(this Texture2D tex, byte[] data)
39
- loadImage = t . GetMethods ( ) . FirstOrDefault ( x => x . Name == "LoadImage" && x . GetParameters ( ) . Length == 2 ) ;
40
40
invokeLoadImage = ( tex , ms ) =>
41
41
{
42
- loadImage . Invoke ( null , new object [ ] { tex , ms . ToArray ( ) } ) ;
42
+ loadImage . Invoke ( tex , new object [ ] { ms . ToArray ( ) } ) ;
43
43
return tex ;
44
44
} ;
45
45
}
46
46
else
47
47
{
48
- // looking for Texture2D.LoadImage(byte[] data)
49
- loadImage = typeof ( Texture2D ) . GetMethods ( ) . FirstOrDefault ( x => x . Name == "LoadImage" && x . GetParameters ( ) . Length == 1 ) ;
50
- invokeLoadImage = ( tex , ms ) =>
48
+ // 2017.1
49
+ var t = typeof ( Texture2D ) . Assembly . GetType ( "UnityEngine.ImageConversion" , false , false ) ;
50
+ if ( t == null )
51
51
{
52
- loadImage . Invoke ( tex , new object [ ] { ms . ToArray ( ) } ) ;
53
- return tex ;
54
- } ;
52
+ // 2017.2 and above
53
+ t = Assembly . Load ( "UnityEngine.ImageConversionModule" ) . GetType ( "UnityEngine.ImageConversion" , false , false ) ;
54
+ }
55
+
56
+ if ( t != null )
57
+ {
58
+ // looking for ImageConversion.LoadImage(this Texture2D tex, byte[] data)
59
+ loadImage = t . GetMethods ( ) . FirstOrDefault ( x => x . Name == "LoadImage" && x . GetParameters ( ) . Length == 2 ) ;
60
+ invokeLoadImage = ( tex , ms ) =>
61
+ {
62
+ loadImage . Invoke ( null , new object [ ] { tex , ms . ToArray ( ) } ) ;
63
+ return tex ;
64
+ } ;
65
+ }
66
+ }
67
+
68
+ if ( loadImage == null )
69
+ {
70
+ Logging . Error ( "Could not find ImageConversion.LoadImage method" ) ;
55
71
}
56
72
}
57
73
0 commit comments