57-Mirror__Network Transform-NewNetworkTransform.cs.txt 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #define onlySyncOnChange_BANDWIDTH_SAVING
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Mirror;
  5. /*
  6. Documentation: https://mirror-networking.gitbook.io/docs/components/network-transform
  7. API Reference: https://mirror-networking.com/docs/api/Mirror.NetworkTransformBase.html
  8. */
  9. public class #SCRIPTNAME# : NetworkTransformBase
  10. {
  11. protected override Transform targetComponent => transform;
  12. // If you need this template to reference a child target,
  13. // replace the line above with the code below.
  14. /*
  15. [Header("Target")]
  16. public Transform target;
  17. protected override Transform targetComponent => target;
  18. */
  19. #region Unity Callbacks
  20. protected override void OnValidate()
  21. {
  22. base.OnValidate();
  23. }
  24. /// <summary>
  25. /// This calls Reset()
  26. /// </summary>
  27. protected override void OnEnable()
  28. {
  29. base.OnEnable();
  30. }
  31. /// <summary>
  32. /// This calls Reset()
  33. /// </summary>
  34. protected override void OnDisable()
  35. {
  36. base.OnDisable();
  37. }
  38. /// <summary>
  39. /// Buffers are cleared and interpolation times are reset to zero here.
  40. /// This may be called when you are implementing some system of not sending
  41. /// if nothing changed, or just plain resetting if you have not received data
  42. /// for some time, as this will prevent a long interpolation period between old
  43. /// and just received data, as it will look like a lag. Reset() should also be
  44. /// called when authority is changed to another client or server, to prevent
  45. /// old buffers bugging out the interpolation if authority is changed back.
  46. /// </summary>
  47. public override void Reset()
  48. {
  49. base.Reset();
  50. }
  51. #endregion
  52. #region NT Base Callbacks
  53. /// <summary>
  54. /// NTSnapshot struct is created from incoming data from server
  55. /// and added to SnapshotInterpolation sorted list.
  56. /// You may want to skip calling the base method for the local player
  57. /// if doing client-side prediction, or perhaps pass altered values,
  58. /// or compare the server data to local values and correct large differences.
  59. /// </summary>
  60. protected override void OnServerToClientSync(Vector3? position, Quaternion? rotation, Vector3? scale)
  61. {
  62. base.OnServerToClientSync(position, rotation, scale);
  63. }
  64. /// <summary>
  65. /// NTSnapshot struct is created from incoming data from client
  66. /// and added to SnapshotInterpolation sorted list.
  67. /// You may want to implement anti-cheat checks here in client authority mode.
  68. /// </summary>
  69. protected override void OnClientToServerSync(Vector3? position, Quaternion? rotation, Vector3? scale)
  70. {
  71. base.OnClientToServerSync(position, rotation, scale);
  72. }
  73. /// <summary>
  74. /// Called by both CmdTeleport and RpcTeleport on server and clients, respectively.
  75. /// Here you can disable a Character Controller before calling the base method,
  76. /// and re-enable it after the base method call to avoid conflicting with it.
  77. /// </summary>
  78. protected override void OnTeleport(Vector3 destination)
  79. {
  80. base.OnTeleport(destination);
  81. }
  82. /// <summary>
  83. /// Called by both CmdTeleport and RpcTeleport on server and clients, respectively.
  84. /// Here you can disable a Character Controller before calling the base method,
  85. /// and re-enable it after the base method call to avoid conflicting with it.
  86. /// </summary>
  87. protected override void OnTeleport(Vector3 destination, Quaternion rotation)
  88. {
  89. base.OnTeleport(destination, rotation);
  90. }
  91. /// <summary>
  92. /// NTSnapshot struct is created here
  93. /// </summary>
  94. protected override NTSnapshot ConstructSnapshot()
  95. {
  96. return base.ConstructSnapshot();
  97. }
  98. /// <summary>
  99. /// localPosition, localRotation, and localScale are set here:
  100. /// interpolated values are used if interpolation is enabled.
  101. /// goal values are used if interpolation is disabled.
  102. /// </summary>
  103. protected override void ApplySnapshot(NTSnapshot start, NTSnapshot goal, NTSnapshot interpolated)
  104. {
  105. base.ApplySnapshot(start, goal, interpolated);
  106. }
  107. #if onlySyncOnChange_BANDWIDTH_SAVING
  108. /// <summary>
  109. /// Returns true if position, rotation AND scale are unchanged, within given sensitivity range.
  110. /// </summary>
  111. protected override bool CompareSnapshots(NTSnapshot currentSnapshot)
  112. {
  113. return base.CompareSnapshots(currentSnapshot);
  114. }
  115. #endif
  116. #endregion
  117. #region GUI
  118. #if UNITY_EDITOR || DEVELOPMENT_BUILD
  119. // OnGUI allocates even if it does nothing. avoid in release.
  120. protected override void OnGUI()
  121. {
  122. base.OnGUI();
  123. }
  124. protected override void DrawGizmos(SortedList<double, NTSnapshot> buffer)
  125. {
  126. base.DrawGizmos(buffer);
  127. }
  128. protected override void OnDrawGizmos()
  129. {
  130. base.OnDrawGizmos();
  131. }
  132. #endif
  133. #endregion
  134. }