You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.1 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Runtime.Serialization;
  4. using UnityEngine;
  5. namespace Networking {
  6. public class Vector3SerializationSurrogate : ISerializationSurrogate
  7. {
  8. // Method called to serialize a Vector3 object
  9. public void GetObjectData(System.Object obj, SerializationInfo info, StreamingContext context)
  10. {
  11. Vector3 v3 = (Vector3)obj;
  12. info.AddValue("x", v3.x);
  13. info.AddValue("y", v3.y);
  14. info.AddValue("z", v3.z);
  15. }
  16. // Method called to deserialize a Vector3 object
  17. public System.Object SetObjectData(System.Object obj, SerializationInfo info,
  18. StreamingContext context, ISurrogateSelector selector)
  19. {
  20. Vector3 v3 = (Vector3)obj;
  21. v3.x = (float)info.GetValue("x", typeof(float));
  22. v3.y = (float)info.GetValue("y", typeof(float));
  23. v3.z = (float)info.GetValue("z", typeof(float));
  24. obj = v3;
  25. return obj;
  26. }
  27. }
  28. public class ColorSerializationSurrogate : ISerializationSurrogate
  29. {
  30. // Method called to serialize a Vector3 object
  31. public void GetObjectData(System.Object obj, SerializationInfo info, StreamingContext context)
  32. {
  33. Color col = (Color)obj;
  34. info.AddValue("r", col.r);
  35. info.AddValue("g", col.g);
  36. info.AddValue("b", col.b);
  37. info.AddValue("a", col.a);
  38. }
  39. // Method called to deserialize a Vector3 object
  40. public System.Object SetObjectData(System.Object obj, SerializationInfo info,
  41. StreamingContext context, ISurrogateSelector selector)
  42. {
  43. Color col = (Color)obj;
  44. col.r = (float)info.GetValue("r", typeof(float));
  45. col.g = (float)info.GetValue("g", typeof(float));
  46. col.b = (float)info.GetValue("b", typeof(float));
  47. col.a = (float)info.GetValue("a", typeof(float));
  48. obj = col;
  49. return obj;
  50. }
  51. }
  52. }