Messages.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using UnityEngine;
  3. namespace Mirror
  4. {
  5. public struct ReadyMessage : NetworkMessage {}
  6. public struct NotReadyMessage : NetworkMessage {}
  7. public struct AddPlayerMessage : NetworkMessage {}
  8. public struct SceneMessage : NetworkMessage
  9. {
  10. public string sceneName;
  11. // Normal = 0, LoadAdditive = 1, UnloadAdditive = 2
  12. public SceneOperation sceneOperation;
  13. public bool customHandling;
  14. }
  15. public enum SceneOperation : byte
  16. {
  17. Normal,
  18. LoadAdditive,
  19. UnloadAdditive
  20. }
  21. public struct CommandMessage : NetworkMessage
  22. {
  23. public uint netId;
  24. public byte componentIndex;
  25. public int functionHash;
  26. // the parameters for the Cmd function
  27. // -> ArraySegment to avoid unnecessary allocations
  28. public ArraySegment<byte> payload;
  29. }
  30. public struct RpcMessage : NetworkMessage
  31. {
  32. public uint netId;
  33. public byte componentIndex;
  34. public int functionHash;
  35. // the parameters for the Cmd function
  36. // -> ArraySegment to avoid unnecessary allocations
  37. public ArraySegment<byte> payload;
  38. }
  39. public struct SpawnMessage : NetworkMessage
  40. {
  41. // netId of new or existing object
  42. public uint netId;
  43. public bool isLocalPlayer;
  44. // Sets hasAuthority on the spawned object
  45. public bool isOwner;
  46. public ulong sceneId;
  47. // If sceneId != 0 then it is used instead of assetId
  48. public Guid assetId;
  49. // Local position
  50. public Vector3 position;
  51. // Local rotation
  52. public Quaternion rotation;
  53. // Local scale
  54. public Vector3 scale;
  55. // serialized component data
  56. // ArraySegment to avoid unnecessary allocations
  57. public ArraySegment<byte> payload;
  58. }
  59. public struct ChangeOwnerMessage : NetworkMessage
  60. {
  61. public uint netId;
  62. public bool isOwner;
  63. public bool isLocalPlayer;
  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. }