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.

146 lines
3.1 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. }
  17. public class PlayerMsg : MessageBase
  18. {
  19. public byte ID;
  20. public PlayerMsg() { }
  21. public PlayerMsg(byte playerID)
  22. {
  23. this.ID = playerID;
  24. }
  25. public override void Serialize(NetworkWriter writer)
  26. {
  27. writer.Write(ID);
  28. }
  29. public override void Deserialize(NetworkReader reader)
  30. {
  31. ID = reader.ReadByte();
  32. }
  33. }
  34. public class VectorMsg : PlayerMsg
  35. {
  36. public Vector3 vector;
  37. public VectorMsg() { }
  38. public VectorMsg(byte PlayerID, Vector3 Vector) : base(PlayerID)
  39. {
  40. this.vector = Vector;
  41. }
  42. public override void Serialize(NetworkWriter writer)
  43. {
  44. base.Serialize(writer);
  45. writer.Write(vector);
  46. }
  47. public override void Deserialize(NetworkReader reader)
  48. {
  49. base.Deserialize(reader);
  50. vector = reader.ReadVector3();
  51. }
  52. }
  53. public class QuaternionMsg : PlayerMsg
  54. {
  55. public Quaternion quaternion;
  56. public QuaternionMsg() { }
  57. public QuaternionMsg(byte PlayerID, Quaternion quaternion) : base(PlayerID)
  58. {
  59. this.quaternion = quaternion;
  60. }
  61. public override void Serialize(NetworkWriter writer)
  62. {
  63. base.Serialize(writer);
  64. writer.Write(quaternion);
  65. }
  66. public override void Deserialize(NetworkReader reader)
  67. {
  68. base.Deserialize(reader);
  69. quaternion = reader.ReadQuaternion();
  70. }
  71. }
  72. public class longMsg : PlayerMsg
  73. {
  74. public long Long;
  75. public longMsg() { }
  76. public longMsg(byte PlayerID, long Long) : base(PlayerID)
  77. {
  78. this.Long = Long;
  79. }
  80. public override void Serialize(NetworkWriter writer)
  81. {
  82. base.Serialize(writer);
  83. writer.Write(Long);
  84. }
  85. public override void Deserialize(NetworkReader reader)
  86. {
  87. base.Deserialize(reader);
  88. Long = reader.ReadInt64();
  89. }
  90. }
  91. public class StringMsg : PlayerMsg
  92. {
  93. public string String;
  94. public StringMsg() { }
  95. public StringMsg(byte PlayerID, string String) : base(PlayerID)
  96. {
  97. this.String = String;
  98. }
  99. public override void Serialize(NetworkWriter writer)
  100. {
  101. base.Serialize(writer);
  102. writer.Write(String);
  103. }
  104. public override void Deserialize(NetworkReader reader)
  105. {
  106. base.Deserialize(reader);
  107. String = reader.ReadString();
  108. }
  109. }
  110. }