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.

207 lines
4.5 KiB

5 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. public class PlayerDataMsg : PlayerMsg
  135. {
  136. public string Name;
  137. public Color Color;
  138. public PlayerDataMsg() { }
  139. public PlayerDataMsg(byte PlayerID, string Name, Color Color) : base(PlayerID)
  140. {
  141. this.Name = Name;
  142. this.Color = Color;
  143. }
  144. public override void Serialize(NetworkWriter writer)
  145. {
  146. base.Serialize(writer);
  147. writer.Write(Name);
  148. writer.Write(Color);
  149. }
  150. public override void Deserialize(NetworkReader reader)
  151. {
  152. base.Deserialize(reader);
  153. Name = reader.ReadString();
  154. Color = reader.ReadColor();
  155. }
  156. }
  157. }