@@ -19,8 +19,11 @@ public class Texture2DSurrogate : ISerializationSurrogate
19
19
public void GetObjectData ( object obj , SerializationInfo info , StreamingContext context )
20
20
{
21
21
Texture2D texture = ( Texture2D ) obj ;
22
+
23
+ #if UNITY_2018_3_OR_NEWER
22
24
if ( ! texture . isReadable )
23
25
throw new System . NotSupportedException ( "Textures must be readable to serialize" ) ;
26
+ #endif
24
27
25
28
var data = texture . GetRawTextureData ( ) ;
26
29
info . AddValue ( ValueName , texture . name ) ;
@@ -36,13 +39,23 @@ public void GetObjectData(object obj, SerializationInfo info, StreamingContext c
36
39
37
40
public object SetObjectData ( object obj , SerializationInfo info , StreamingContext context , ISurrogateSelector selector )
38
41
{
42
+ #if UNITY_2021_OR_NEWER
39
43
Texture2D texture = new Texture2D (
40
44
info . GetInt32 ( ValueWidth ) ,
41
45
info . GetInt32 ( ValueHeight ) ,
42
46
( TextureFormat ) info . GetInt32 ( ValueFormat ) ,
43
47
info . GetInt32 ( ValueMipmap ) ,
44
48
false
45
49
) ;
50
+ #else
51
+ Texture2D texture = new Texture2D (
52
+ info . GetInt32 ( ValueWidth ) ,
53
+ info . GetInt32 ( ValueHeight ) ,
54
+ ( TextureFormat ) info . GetInt32 ( ValueFormat ) ,
55
+ true ,
56
+ false
57
+ ) ;
58
+ #endif
46
59
47
60
texture . filterMode = ( FilterMode ) info . GetInt32 ( ValueFilter ) ;
48
61
texture . wrapMode = ( TextureWrapMode ) info . GetInt32 ( ValueWrap ) ;
0 commit comments