@@ -32,26 +32,42 @@ static class StreamExtensions
3232
3333 static StreamExtensions ( )
3434 {
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 )
3739 {
38- // looking for ImageConversion.LoadImage(this Texture2D tex, byte[] data)
39- loadImage = t . GetMethods ( ) . FirstOrDefault ( x => x . Name == "LoadImage" && x . GetParameters ( ) . Length == 2 ) ;
4040 invokeLoadImage = ( tex , ms ) =>
4141 {
42- loadImage . Invoke ( null , new object [ ] { tex , ms . ToArray ( ) } ) ;
42+ loadImage . Invoke ( tex , new object [ ] { ms . ToArray ( ) } ) ;
4343 return tex ;
4444 } ;
4545 }
4646 else
4747 {
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 )
5151 {
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" ) ;
5571 }
5672 }
5773
0 commit comments