using UnityEngine;
namespace FishNet.Managing.Statistic
{
[DisallowMultipleComponent]
[AddComponentMenu("FishNet/Manager/StatisticsManager")]
public class StatisticsManager : MonoBehaviour
{
///
/// True to operate while in release. This may cause allocations and impact performance.
///
[Tooltip("True to operate while in release. This may cause allocations and impact performance.")]
[SerializeField]
private bool _runInRelease;
///
/// Statistics for NetworkTraffic.
///
[Tooltip("Statistics for NetworkTraffic.")]
[SerializeField]
private NetworkTrafficStatistics _networkTraffic;
///
/// NetworkManager this is for.
///
private NetworkManager _networkManager;
internal void InitializeOnce_Internal(NetworkManager manager)
{
_networkManager = manager;
}
///
/// Gets NetworkTrafficStatistics reference.
///
public bool TryGetNetworkTrafficStatistics(out NetworkTrafficStatistics statistics)
{
statistics = null;
/* Cannot run in the current build type. */
#if (!UNITY_EDITOR && !DEVELOPMENT_BUILD) || UNITY_SERVER
if (!_runInRelease)
{
_networkTraffic = null;
return false;
}
#endif
//NetworkManager must be set to work.
if (_networkManager == null)
{
if (!TryGetComponent(out _networkManager))
return false;
}
//Hot-load if needed.
if (_networkTraffic == null)
_networkTraffic = new();
_networkTraffic.InitializeOnce_Internal(_networkManager);
if (_networkTraffic.IsEnabled())
statistics = _networkTraffic;
return statistics != null;
}
}
}