using FishNet.Object;
using GameKit.Dependencies.Utilities;
using UnityEngine;
namespace FishNet.Component.Transforming.Beta
{
///
/// Smoothes this object between ticks.
///
/// This can be configured to smooth over a set interval of time, or to smooth adaptively and make path corrections for prediction.
public class NetworkTickSmoother : NetworkBehaviour
{
#region Public.
///
/// Logic for owner smoothing.
///
public TickSmootherController SmootherController { get; private set; }
#endregion
///
/// Settings required to initialize the smoother.
///
[Tooltip("Settings required to initialize the smoother.")]
[SerializeField]
private InitializationSettings _initializationSettings = new();
///
/// How smoothing occurs when the controller of the object.
///
[Tooltip("How smoothing occurs when the controller of the object.")]
[SerializeField]
private MovementSettings _controllerMovementSettings = new(true);
///
/// How smoothing occurs when spectating the object.
///
[Tooltip("How smoothing occurs when spectating the object.")]
[SerializeField]
private MovementSettings _spectatorMovementSettings = new(true);
private void OnDestroy()
{
if (SmootherController != null)
SmootherController.OnDestroy();
StoreControllers();
}
public override void OnStartClient()
{
RetrieveControllers();
_initializationSettings.SetNetworkedRuntimeValues(initializingNetworkBehaviour: this, graphicalTransform: transform);
SmootherController.Initialize(_initializationSettings, _controllerMovementSettings, _spectatorMovementSettings);
SmootherController.StartSmoother();
}
public override void OnStopClient()
{
if (SmootherController == null)
return;
SmootherController.StopSmoother();
}
///
/// Stores smoothers if they have value.
///
private void StoreControllers()
{
if (SmootherController == null)
return;
ResettableObjectCaches.Store(SmootherController);
SmootherController = null;
}
///
/// Stores current smoothers and retrieves new ones.
///
private void RetrieveControllers()
{
StoreControllers();
SmootherController = ResettableObjectCaches.Retrieve();
}
}
}