feat: Added Network Transform Script Template

This commit is contained in:
MrGadget1024 2021-10-30 12:33:19 -04:00
parent 74f7cb168f
commit 429e80dde3
2 changed files with 149 additions and 0 deletions

View File

@ -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();
}
/// <summary>
/// This calls Reset()
/// </summary>
protected override void OnEnable()
{
base.OnEnable();
}
/// <summary>
/// This calls Reset()
/// </summary>
protected override void OnDisable()
{
base.OnDisable();
}
/// <summary>
/// <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>
/// </summary>
protected 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-enabling it after the base method call to avoid conflicting with it.
/// </summary>
protected override void OnTeleport(Vector3 destination)
{
base.OnTeleport(destination);
}
/// <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);
}
#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
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 38d41e2048919f64ea817eb343ffb09d
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: