From 429e80dde3aa579358a5f110390836e2a99db475 Mon Sep 17 00:00:00 2001 From: MrGadget1024 Date: Sat, 30 Oct 2021 12:33:19 -0400 Subject: [PATCH] feat: Added Network Transform Script Template --- ...twork Transform-NewNetworkTransform.cs.txt | 142 ++++++++++++++++++ ... Transform-NewNetworkTransform.cs.txt.meta | 7 + 2 files changed, 149 insertions(+) create mode 100644 Assets/ScriptTemplates/57-Mirror__Network Transform-NewNetworkTransform.cs.txt create mode 100644 Assets/ScriptTemplates/57-Mirror__Network Transform-NewNetworkTransform.cs.txt.meta diff --git a/Assets/ScriptTemplates/57-Mirror__Network Transform-NewNetworkTransform.cs.txt b/Assets/ScriptTemplates/57-Mirror__Network Transform-NewNetworkTransform.cs.txt new file mode 100644 index 000000000..aa6e53b62 --- /dev/null +++ b/Assets/ScriptTemplates/57-Mirror__Network Transform-NewNetworkTransform.cs.txt @@ -0,0 +1,142 @@ +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(); + } + + /// + /// This calls Reset() + /// + protected override void OnEnable() + { + base.OnEnable(); + } + + /// + /// This calls Reset() + /// + protected override void OnDisable() + { + base.OnDisable(); + } + + /// + /// + /// 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. + /// + /// + protected override void Reset() + { + base.Reset(); + } + + #endregion + + #region NT Base Callbacks + + /// + /// 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. + /// + protected override void OnServerToClientSync(Vector3? position, Quaternion? rotation, Vector3? scale) + { + base.OnServerToClientSync(position, rotation, scale); + } + + /// + /// 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. + /// + protected override void OnClientToServerSync(Vector3? position, Quaternion? rotation, Vector3? scale) + { + base.OnClientToServerSync(position, rotation, scale); + } + + /// + /// 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-enabling it after the base method call to avoid conflicting with it. + /// + protected override void OnTeleport(Vector3 destination) + { + base.OnTeleport(destination); + } + + /// + /// NTSnapshot struct is created here + /// + protected override NTSnapshot ConstructSnapshot() + { + return base.ConstructSnapshot(); + } + + /// + /// localPosition, localRotation, and localScale are set here: + /// interpolated values are used if interpolation is enabled. + /// goal values are used if interpolation is disabled. + /// + protected override void ApplySnapshot(NTSnapshot start, NTSnapshot goal, NTSnapshot interpolated) + { + base.ApplySnapshot(start, goal, interpolated); + } + + #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 buffer) + { + base.DrawGizmos(buffer); + } + + protected override void OnDrawGizmos() + { + base.OnDrawGizmos(); + } + +#endif + + #endregion +} diff --git a/Assets/ScriptTemplates/57-Mirror__Network Transform-NewNetworkTransform.cs.txt.meta b/Assets/ScriptTemplates/57-Mirror__Network Transform-NewNetworkTransform.cs.txt.meta new file mode 100644 index 000000000..be7e6d736 --- /dev/null +++ b/Assets/ScriptTemplates/57-Mirror__Network Transform-NewNetworkTransform.cs.txt.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 38d41e2048919f64ea817eb343ffb09d +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: