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.

55 lines
1.4 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. namespace Networking
  6. {
  7. public class LogicProtocols
  8. {
  9. public const short SendLogicList = 200;
  10. public class LogicMsg : MessageBase
  11. {
  12. public LogicBlock[] elements;
  13. public LogicMsg() { }
  14. public LogicMsg(LogicBlock[] elements)
  15. {
  16. this.elements = elements;
  17. }
  18. public override void Serialize(NetworkWriter writer)
  19. {
  20. base.Serialize(writer);
  21. writer.Write(elements.Length);
  22. foreach (LogicBlock block in elements)
  23. {
  24. BlockToken token = block.ToToken();
  25. byte[] bytes = Utility.ObjectToByteArray(token);
  26. writer.WriteBytesAndSize(bytes,bytes.Length);
  27. }
  28. }
  29. public override void Deserialize(NetworkReader reader)
  30. {
  31. base.Deserialize(reader);
  32. int count = reader.ReadInt32();
  33. elements = new LogicBlock[count];
  34. for (int i = 0; i < count; i++)
  35. {
  36. BlockToken token = Utility.ByteArrayToObject<BlockToken>(reader.ReadBytesAndSize());
  37. elements[i] = token.ToLogicBlock();
  38. }
  39. }
  40. }
  41. }
  42. }