Guest User

Untitled

a guest
Jan 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. [Serializable]
  2. public class Illustration : ISerializable
  3. {
  4. public Texture2D Image = new Texture2D(256, 256);
  5.  
  6. public void GetObjectData(SerializationInfo info, StreamingContext context)
  7. {
  8. info.AddValue(nameof(Image), Image.EncodeToPNG(), typeof(byte[]));
  9. }
  10.  
  11. private Illustration(SerializationInfo info, StreamingContext context)
  12. {
  13. Image.LoadImage(info.GetValue(nameof(Image), typeof(byte[])) as byte[]);
  14. }
  15. }
  16.  
  17. [Serializable]
  18. public class CustomAnimation : ISerializable
  19. {
  20. public Texture2D[] Images;
  21.  
  22. public void GetObjectData(SerializationInfo info, StreamingContext context)
  23. {
  24. info.AddValue(nameof(Images), Images.Select(x => x.EncodeToPNG()).ToArray(), typeof(byte[][]));
  25. }
  26.  
  27. private CustomAnimation(SerializationInfo info, StreamingContext context)
  28. {
  29. var textures = info.GetValue(nameof(Images), typeof(byte[][])) as byte[][];
  30. if (textures != null)
  31. {
  32. var imagesAndTextures = Images.Zip(textures, (i, t) => new {Images = i, textures = t});
  33. foreach (var it in imagesAndTextures)
  34. {
  35. it.Images.LoadImage(it.textures);
  36. }
  37. }
  38. }
  39. }
  40.  
  41. "Illustrations": [
  42. {
  43. "Image": {
  44. "instanceID": 34540
  45. }
  46. }
  47. ]
Add Comment
Please, Sign In to add comment