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.

116 lines
2.4 KiB

  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. }
  12. public class PlayerMsg : MessageBase
  13. {
  14. public byte ID;
  15. public PlayerMsg() { }
  16. public PlayerMsg(byte playerID)
  17. {
  18. this.ID = playerID;
  19. }
  20. public override void Serialize(NetworkWriter writer)
  21. {
  22. writer.Write(ID);
  23. }
  24. public override void Deserialize(NetworkReader reader)
  25. {
  26. ID = reader.ReadByte();
  27. }
  28. }
  29. public class VectorMsg : PlayerMsg
  30. {
  31. public Vector3 vector;
  32. public VectorMsg() { }
  33. public VectorMsg(byte PlayerID, Vector3 Vector) : base(PlayerID)
  34. {
  35. this.vector = Vector;
  36. }
  37. public override void Serialize(NetworkWriter writer)
  38. {
  39. base.Serialize(writer);
  40. writer.Write(vector);
  41. }
  42. public override void Deserialize(NetworkReader reader)
  43. {
  44. base.Deserialize(reader);
  45. vector = reader.ReadVector3();
  46. }
  47. }
  48. public class QuaternionMsg : PlayerMsg
  49. {
  50. public Quaternion quaternion;
  51. public QuaternionMsg() { }
  52. public QuaternionMsg(byte PlayerID, Quaternion quaternion) : base(PlayerID)
  53. {
  54. this.quaternion = quaternion;
  55. }
  56. public override void Serialize(NetworkWriter writer)
  57. {
  58. base.Serialize(writer);
  59. writer.Write(quaternion);
  60. }
  61. public override void Deserialize(NetworkReader reader)
  62. {
  63. base.Deserialize(reader);
  64. quaternion = reader.ReadQuaternion();
  65. }
  66. }
  67. public class StringMsg : PlayerMsg
  68. {
  69. public string String;
  70. public StringMsg() { }
  71. public StringMsg(byte PlayerID, string String) : base(PlayerID)
  72. {
  73. this.String = String;
  74. }
  75. public override void Serialize(NetworkWriter writer)
  76. {
  77. base.Serialize(writer);
  78. writer.Write(String);
  79. }
  80. public override void Deserialize(NetworkReader reader)
  81. {
  82. base.Deserialize(reader);
  83. String = reader.ReadString();
  84. }
  85. }
  86. }