123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- #define onlySyncOnChange_BANDWIDTH_SAVING
- using System.Collections.Generic;
- using UnityEngine;
- using Mirror;
- /*
- Documentation: https://mirror-networking.gitbook.io/docs/components/network-transform
- API Reference: https://mirror-networking.com/docs/api/Mirror.NetworkTransformBase.html
- */
- public class #SCRIPTNAME# : NetworkTransformBase
- {
- protected override Transform targetComponent => transform;
- // If you need this template to reference a child target,
- // replace the line above with the code below.
- /*
- [Header("Target")]
- public Transform target;
- protected override Transform targetComponent => target;
- */
- #region Unity Callbacks
- protected override void OnValidate()
- {
- base.OnValidate();
- }
- /// <summary>
- /// This calls Reset()
- /// </summary>
- protected override void OnEnable()
- {
- base.OnEnable();
- }
- /// <summary>
- /// This calls Reset()
- /// </summary>
- protected override void OnDisable()
- {
- base.OnDisable();
- }
- /// <summary>
- /// Buffers are cleared and interpolation times are reset to zero here.
- /// This may be called when you are implementing some system of not sending
- /// if nothing changed, or just plain resetting if you have not received data
- /// for some time, as this will prevent a long interpolation period between old
- /// and just received data, as it will look like a lag. Reset() should also be
- /// called when authority is changed to another client or server, to prevent
- /// old buffers bugging out the interpolation if authority is changed back.
- /// </summary>
- public override void Reset()
- {
- base.Reset();
- }
- #endregion
- #region NT Base Callbacks
- /// <summary>
- /// NTSnapshot struct is created from incoming data from server
- /// and added to SnapshotInterpolation sorted list.
- /// You may want to skip calling the base method for the local player
- /// if doing client-side prediction, or perhaps pass altered values,
- /// or compare the server data to local values and correct large differences.
- /// </summary>
- protected override void OnServerToClientSync(Vector3? position, Quaternion? rotation, Vector3? scale)
- {
- base.OnServerToClientSync(position, rotation, scale);
- }
- /// <summary>
- /// NTSnapshot struct is created from incoming data from client
- /// and added to SnapshotInterpolation sorted list.
- /// You may want to implement anti-cheat checks here in client authority mode.
- /// </summary>
- protected override void OnClientToServerSync(Vector3? position, Quaternion? rotation, Vector3? scale)
- {
- base.OnClientToServerSync(position, rotation, scale);
- }
- /// <summary>
- /// Called by both CmdTeleport and RpcTeleport on server and clients, respectively.
- /// Here you can disable a Character Controller before calling the base method,
- /// and re-enable it after the base method call to avoid conflicting with it.
- /// </summary>
- protected override void OnTeleport(Vector3 destination)
- {
- base.OnTeleport(destination);
- }
- /// <summary>
- /// Called by both CmdTeleport and RpcTeleport on server and clients, respectively.
- /// Here you can disable a Character Controller before calling the base method,
- /// and re-enable it after the base method call to avoid conflicting with it.
- /// </summary>
- protected override void OnTeleport(Vector3 destination, Quaternion rotation)
- {
- base.OnTeleport(destination, rotation);
- }
- /// <summary>
- /// NTSnapshot struct is created here
- /// </summary>
- protected override NTSnapshot ConstructSnapshot()
- {
- return base.ConstructSnapshot();
- }
- /// <summary>
- /// localPosition, localRotation, and localScale are set here:
- /// interpolated values are used if interpolation is enabled.
- /// goal values are used if interpolation is disabled.
- /// </summary>
- protected override void ApplySnapshot(NTSnapshot start, NTSnapshot goal, NTSnapshot interpolated)
- {
- base.ApplySnapshot(start, goal, interpolated);
- }
- #if onlySyncOnChange_BANDWIDTH_SAVING
- /// <summary>
- /// Returns true if position, rotation AND scale are unchanged, within given sensitivity range.
- /// </summary>
- protected override bool CompareSnapshots(NTSnapshot currentSnapshot)
- {
- return base.CompareSnapshots(currentSnapshot);
- }
- #endif
- #endregion
- #region GUI
- #if UNITY_EDITOR || DEVELOPMENT_BUILD
- // OnGUI allocates even if it does nothing. avoid in release.
- protected override void OnGUI()
- {
- base.OnGUI();
- }
- protected override void DrawGizmos(SortedList<double, NTSnapshot> buffer)
- {
- base.DrawGizmos(buffer);
- }
- protected override void OnDrawGizmos()
- {
- base.OnDrawGizmos();
- }
- #endif
- #endregion
- }
|