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.

176 lines
3.8 KiB

6 years ago
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. namespace Multiplayer
  6. {
  7. public class PlayerMsgID
  8. {
  9. public const short Position = 200;
  10. public const short Rotation = 201;
  11. public const short Lobby = 202;
  12. public const short GameWin = 203;
  13. public const short GameOver = 204;
  14. public const short GameStart = 205;
  15. public const short QueryPosition = 206;
  16. public const short Vegetable = 207;
  17. }
  18. public class PlayerMsg : MessageBase
  19. {
  20. public byte ID;
  21. public PlayerMsg() { }
  22. public PlayerMsg(byte playerID)
  23. {
  24. this.ID = playerID;
  25. }
  26. public override void Serialize(NetworkWriter writer)
  27. {
  28. writer.Write(ID);
  29. }
  30. public override void Deserialize(NetworkReader reader)
  31. {
  32. ID = reader.ReadByte();
  33. }
  34. }
  35. public class VectorMsg : PlayerMsg
  36. {
  37. public Vector3 vector;
  38. public VectorMsg() { }
  39. public VectorMsg(byte PlayerID, Vector3 Vector) : base(PlayerID)
  40. {
  41. this.vector = Vector;
  42. }
  43. public override void Serialize(NetworkWriter writer)
  44. {
  45. base.Serialize(writer);
  46. writer.Write(vector);
  47. }
  48. public override void Deserialize(NetworkReader reader)
  49. {
  50. base.Deserialize(reader);
  51. vector = reader.ReadVector3();
  52. }
  53. }
  54. public class QuaternionMsg : PlayerMsg
  55. {
  56. public Quaternion quaternion;
  57. public QuaternionMsg() { }
  58. public QuaternionMsg(byte PlayerID, Quaternion quaternion) : base(PlayerID)
  59. {
  60. this.quaternion = quaternion;
  61. }
  62. public override void Serialize(NetworkWriter writer)
  63. {
  64. base.Serialize(writer);
  65. writer.Write(quaternion);
  66. }
  67. public override void Deserialize(NetworkReader reader)
  68. {
  69. base.Deserialize(reader);
  70. quaternion = reader.ReadQuaternion();
  71. }
  72. }
  73. public class longMsg : PlayerMsg
  74. {
  75. public long Long;
  76. public longMsg() { }
  77. public longMsg(byte PlayerID, long Long) : base(PlayerID)
  78. {
  79. this.Long = Long;
  80. }
  81. public override void Serialize(NetworkWriter writer)
  82. {
  83. base.Serialize(writer);
  84. writer.Write(Long);
  85. }
  86. public override void Deserialize(NetworkReader reader)
  87. {
  88. base.Deserialize(reader);
  89. Long = reader.ReadInt64();
  90. }
  91. }
  92. public class StringMsg : PlayerMsg
  93. {
  94. public string String;
  95. public StringMsg() { }
  96. public StringMsg(byte PlayerID, string String) : base(PlayerID)
  97. {
  98. this.String = String;
  99. }
  100. public override void Serialize(NetworkWriter writer)
  101. {
  102. base.Serialize(writer);
  103. writer.Write(String);
  104. }
  105. public override void Deserialize(NetworkReader reader)
  106. {
  107. base.Deserialize(reader);
  108. String = reader.ReadString();
  109. }
  110. }
  111. public class VegMsg : PlayerMsg
  112. {
  113. public string String;
  114. public int Int;
  115. public VegMsg() { }
  116. public VegMsg(byte PlayerID, string String, int Int) : base(PlayerID)
  117. {
  118. this.String = String;
  119. this.Int = Int;
  120. }
  121. public override void Serialize(NetworkWriter writer)
  122. {
  123. base.Serialize(writer);
  124. writer.Write(String);
  125. writer.Write(Int);
  126. }
  127. public override void Deserialize(NetworkReader reader)
  128. {
  129. base.Deserialize(reader);
  130. String = reader.ReadString();
  131. Int = reader.ReadInt32();
  132. }
  133. }
  134. }