Messages.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using UnityEngine;
  3. namespace Mirror
  4. {
  5. // Deprecated 2020-10-06
  6. [Obsolete("Implement NetworkMessage instead. Use extension methods instead of Serialize/Deserialize, see https://github.com/vis2k/Mirror/pull/2317", true)]
  7. public interface IMessageBase {}
  8. // Deprecated 2020-10-06
  9. [Obsolete("Implement NetworkMessage instead. Use extension methods instead of Serialize/Deserialize, see https://github.com/vis2k/Mirror/pull/2317", true)]
  10. public class MessageBase : IMessageBase {}
  11. public struct ReadyMessage : NetworkMessage {}
  12. public struct NotReadyMessage : NetworkMessage {}
  13. public struct AddPlayerMessage : NetworkMessage {}
  14. public struct SceneMessage : NetworkMessage
  15. {
  16. public string sceneName;
  17. // Normal = 0, LoadAdditive = 1, UnloadAdditive = 2
  18. public SceneOperation sceneOperation;
  19. public bool customHandling;
  20. }
  21. public enum SceneOperation : byte
  22. {
  23. Normal,
  24. LoadAdditive,
  25. UnloadAdditive
  26. }
  27. public struct CommandMessage : NetworkMessage
  28. {
  29. public uint netId;
  30. public int componentIndex;
  31. public int functionHash;
  32. // the parameters for the Cmd function
  33. // -> ArraySegment to avoid unnecessary allocations
  34. public ArraySegment<byte> payload;
  35. }
  36. public struct RpcMessage : NetworkMessage
  37. {
  38. public uint netId;
  39. public int componentIndex;
  40. public int functionHash;
  41. // the parameters for the Cmd function
  42. // -> ArraySegment to avoid unnecessary allocations
  43. public ArraySegment<byte> payload;
  44. }
  45. public struct SpawnMessage : NetworkMessage
  46. {
  47. // netId of new or existing object
  48. public uint netId;
  49. public bool isLocalPlayer;
  50. // Sets hasAuthority on the spawned object
  51. public bool isOwner;
  52. public ulong sceneId;
  53. // If sceneId != 0 then it is used instead of assetId
  54. public Guid assetId;
  55. // Local position
  56. public Vector3 position;
  57. // Local rotation
  58. public Quaternion rotation;
  59. // Local scale
  60. public Vector3 scale;
  61. // serialized component data
  62. // ArraySegment to avoid unnecessary allocations
  63. public ArraySegment<byte> payload;
  64. }
  65. public struct ObjectSpawnStartedMessage : NetworkMessage {}
  66. public struct ObjectSpawnFinishedMessage : NetworkMessage {}
  67. public struct ObjectDestroyMessage : NetworkMessage
  68. {
  69. public uint netId;
  70. }
  71. public struct ObjectHideMessage : NetworkMessage
  72. {
  73. public uint netId;
  74. }
  75. public struct EntityStateMessage : NetworkMessage
  76. {
  77. public uint netId;
  78. // the serialized component data
  79. // -> ArraySegment to avoid unnecessary allocations
  80. public ArraySegment<byte> payload;
  81. }
  82. // A client sends this message to the server
  83. // to calculate RTT and synchronize time
  84. public struct NetworkPingMessage : NetworkMessage
  85. {
  86. public double clientTime;
  87. public NetworkPingMessage(double value)
  88. {
  89. clientTime = value;
  90. }
  91. }
  92. // The server responds with this message
  93. // The client can use this to calculate RTT and sync time
  94. public struct NetworkPongMessage : NetworkMessage
  95. {
  96. public double clientTime;
  97. public double serverTime;
  98. }
  99. }