Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Assets/FishNet/CodeGenerating/Unity.FishNet.CodeGen.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"references": [
"FishNet.Runtime",
"FishNet.Codegen.Cecil",
"GameKit.Dependencies"
"GameKit.Dependencies",
"Unity.Burst",
"Unity.Mathematics",
"Unity.Collections"
],
"includePlatforms": [
"Editor"
Expand Down
2 changes: 1 addition & 1 deletion Assets/FishNet/Runtime/CodeGenerating/Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class NotSerializerAttribute : Attribute { }
/// <summary>
/// Method or type will be made public by codegen.
/// </summary>
internal class MakePublicAttribute : Attribute { }
public class MakePublicAttribute : Attribute { }

/// <summary>
/// Method is a comparer for a value type.
Expand Down
8 changes: 4 additions & 4 deletions Assets/FishNet/Runtime/Connection/NetworkConnection.QOL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public string GetAddress()
/// <param name = "kickReason">Reason client is being kicked.</param>
/// <param name = "loggingType">How to print logging as.</param>
/// <param name = "log">Optional message to be debug logged.</param>
public void Kick(KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "")
public void Kick(KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "", bool immediately = true)
{
if (CanKick())
NetworkManager.ServerManager.Kick(this, kickReason, loggingType, log);
NetworkManager.ServerManager.Kick(this, kickReason, loggingType, log, immediately);
}

/// <summary>
Expand All @@ -56,10 +56,10 @@ public void Kick(KickReason kickReason, LoggingType loggingType = LoggingType.Co
/// <param name = "kickReason">Reason client is being kicked.</param>
/// <param name = "loggingType">How to print logging as.</param>
/// <param name = "log">Optional message to be debug logged.</param>
public void Kick(Reader reader, KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "")
public void Kick(Reader reader, KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "", bool immediately = true)
{
if (CanKick())
NetworkManager.ServerManager.Kick(this, reader, kickReason, loggingType, log);
NetworkManager.ServerManager.Kick(this, reader, kickReason, loggingType, log, immediately);
}

private bool CanKick()
Expand Down
4 changes: 3 additions & 1 deletion Assets/FishNet/Runtime/FishNet.Runtime.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"references": [
"GUID:894a6cc6ed5cd2645bb542978cbed6a9",
"GUID:1d82bdf40e2465b44b34adf79595e74c",
"GUID:d8b63aba1907145bea998dd612889d6b"
"GUID:d8b63aba1907145bea998dd612889d6b",
"GUID:2665a8d13d1b3f18800f46e256720795",
"GUID:e0cd26848372d4e5c891c569017e11f1"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using FishNet.Managing;
using Unity.Profiling;
using UnityEngine;
using UnityEngine.Profiling;
using Unity.Profiling;
using TimeManagerCls = FishNet.Managing.Timing.TimeManager;

namespace FishNet.Component.Animating
Expand All @@ -33,6 +34,7 @@ private struct ReceivedServerData
/// <summary>
/// Gets an Arraysegment of received data.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public ArraySegment<byte> GetArraySegment() => new(_data, 0, _length);

/// <summary>
Expand All @@ -51,6 +53,7 @@ public ReceivedServerData(ArraySegment<byte> segment)
Buffer.BlockCopy(segment.Array, segment.Offset, _data, 0, _length);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
if (_data != null)
Expand Down Expand Up @@ -210,6 +213,7 @@ public void GetBuffer(int index, ref byte[] buffer, ref int length)
/// <summary>
/// Resets buffers.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Reset()
{
BufferCount = 0;
Expand Down Expand Up @@ -274,6 +278,23 @@ public ParameterDetail(AnimatorControllerParameter controllerParameter, byte typ
}
#endregion

#region Private

#region Private Profiler Markers

private static readonly ProfilerMarker _pm_OnPreTick = new ProfilerMarker("NetworkAnimator.TimeManager_OnPreTick()");
private static readonly ProfilerMarker _pm_OnPostTick = new ProfilerMarker("NetworkAnimator.TimeManager_OnPostTick()");
private static readonly ProfilerMarker _pm_OnUpdate = new ProfilerMarker("NetworkAnimator.TimeManager_OnUpdate()");
private static readonly ProfilerMarker _pm_CheckSendToServer = new ProfilerMarker("NetworkAnimator.CheckSendToServer()");
private static readonly ProfilerMarker _pm_CheckSendToClients = new ProfilerMarker("NetworkAnimator.CheckSendToClients()");
private static readonly ProfilerMarker _pm_SmoothFloats = new ProfilerMarker("NetworkAnimator.SmoothFloats()");
private static readonly ProfilerMarker _pm_AnimatorUpdated = new ProfilerMarker("NetworkAnimator.AnimatorUpdated(ref ArraySegment<byte>, bool)");
private static readonly ProfilerMarker _pm_ApplyParametersUpdated = new ProfilerMarker("NetworkAnimator.ApplyParametersUpdated(ref ArraySegment<byte>)");

#endregion

#endregion

#region Public.
/// <summary>
/// Parameters which will not be synchronized.
Expand Down Expand Up @@ -304,6 +325,14 @@ public Animator Animator
[SerializeField]
private bool _synchronizeWhenDisabled;
/// <summary>
/// True to synchronize changes even when the animator component is disabled.
/// </summary>
public bool SynchronizeWhenDisabled
{
get { return _synchronizeWhenDisabled; }
set { _synchronizeWhenDisabled = value; }
}
/// <summary>
/// True to smooth float value changes for spectators.
/// </summary>
[Tooltip("True to smooth float value changes for spectators.")]
Expand Down Expand Up @@ -334,6 +363,11 @@ public bool ClientAuthoritative
[Tooltip("True to synchronize server results back to owner. Typically used when you are changing animations on the server and are relying on the server response to update the clients animations.")]
[SerializeField]
private bool _sendToOwner;
/// <summary>
/// True to synchronize server results back to owner. Typically used when you are changing animations on the server and are relying on the server response to update the clients animations.
/// </summary>
public bool SendToOwner => _sendToOwner;

#endregion

#region Private.
Expand Down Expand Up @@ -370,12 +404,19 @@ public bool ClientAuthoritative
// /// </summary>
// private List<byte[]> _toClientsBuffer = new();
/// <summary>
/// Synchronization enabled state. True by default
/// </summary>
private bool _isSynchronizationEnabled = true;
/// <summary>
/// Returns if the animator is exist and can be synchronized.
/// </summary>
private bool _canSynchronizeAnimator
{
get
{
if (!_isSynchronizationEnabled)
return false;

if (!_isAnimatorSet)
return false;

Expand Down Expand Up @@ -459,17 +500,6 @@ private bool _canSmoothFloats
private bool _subscribedToTicks;
#endregion

#region Private Profiler Markers
private static readonly ProfilerMarker _pm_OnPreTick = new("NetworkAnimator.TimeManager_OnPreTick()");
private static readonly ProfilerMarker _pm_OnPostTick = new("NetworkAnimator.TimeManager_OnPostTick()");
private static readonly ProfilerMarker _pm_OnUpdate = new("NetworkAnimator.TimeManager_OnUpdate()");
private static readonly ProfilerMarker _pm_CheckSendToServer = new("NetworkAnimator.CheckSendToServer()");
private static readonly ProfilerMarker _pm_CheckSendToClients = new("NetworkAnimator.CheckSendToClients()");
private static readonly ProfilerMarker _pm_SmoothFloats = new("NetworkAnimator.SmoothFloats()");
private static readonly ProfilerMarker _pm_AnimatorUpdated = new("NetworkAnimator.AnimatorUpdated(ref ArraySegment<byte>, bool)");
private static readonly ProfilerMarker _pm_ApplyParametersUpdated = new("NetworkAnimator.ApplyParametersUpdated(ref ArraySegment<byte>)");
#endregion

#region Const.
///// <summary>
///// How much time to fall behind when using smoothing. Only increase value if the smoothing is sometimes jittery. Recommended values are between 0 and 0.04.
Expand Down Expand Up @@ -515,6 +545,7 @@ public override void OnSpawnServer(NetworkConnection connection)
public override void OnStartNetwork()
{
ChangeTickSubscription(true);
_isSynchronizationEnabled = true;
}

[APIExclude]
Expand Down Expand Up @@ -584,6 +615,7 @@ private void TimeManager_OnPreTick()
_fromServerBuffer.Clear();
return;
}

//Disabled/cannot start.
if (_startTick == 0)
return;
Expand All @@ -593,6 +625,7 @@ private void TimeManager_OnPreTick()
_startTick = 0;
return;
}

//Not enough time has passed to start queue.
if (TimeManager.LocalTick < _startTick)
return;
Expand Down Expand Up @@ -645,7 +678,7 @@ private void InitializeOnce()
//Don't run the rest if not in play mode.
if (!ApplicationState.IsPlaying())
return;

if (!_canSynchronizeAnimator)
{
//Debug.LogWarning("Animator is null or not enabled; unable to initialize for animator. Use SetAnimator if animator was changed or enable the animator.");
Expand Down Expand Up @@ -708,6 +741,15 @@ private void InitializeOnce()
}
}
}

/// <summary>
/// Sets synchronization state to NetworkAnimator. Enabled by default.
/// </summary>
/// <param name = "state"></param>
public void SetSynchronizationState(bool state)
{
_isSynchronizationEnabled = state;
}

/// <summary>
/// Sets which animator to use. You must call this with the appropriate animator on all clients and server. This change is not automatically synchronized.
Expand Down Expand Up @@ -846,6 +888,7 @@ private void CheckSendToClients()

SendSegment(new(buffer, 0, bufferLength));
}

//Reset client auth buffer.
_clientAuthoritativeUpdates.Reset();
}
Expand Down Expand Up @@ -978,6 +1021,7 @@ private bool AnimatorUpdated(out ArraySegment<byte> updatedBytes, bool forceAll
_writer.WriteUInt8Unpacked(_triggerUpdates[i].ParameterIndex);
_writer.WriteBoolean(_triggerUpdates[i].Setting);
}

_triggerUpdates.Clear();

/* States. */
Expand Down Expand Up @@ -1069,7 +1113,7 @@ private bool AnimatorUpdated(out ArraySegment<byte> updatedBytes, bool forceAll
//Nothing to update.
if (_writer.Position == 0)
return false;

updatedBytes = _writer.GetArraySegment();
return true;
}
Expand Down Expand Up @@ -1225,6 +1269,7 @@ private bool ReturnCurrentLayerState(out int stateHash, out float normalizedTime
/// Immediately sends all variables and states of layers.
/// This is a very bandwidth intensive operation.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SendAll()
{
_forceAllOnTimed = true;
Expand All @@ -1234,6 +1279,7 @@ public void SendAll()
/// <summary>
/// Plays a state.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Play(string name)
{
Play(Animator.StringToHash(name));
Expand All @@ -1242,6 +1288,7 @@ public void Play(string name)
/// <summary>
/// Plays a state.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Play(int hash)
{
for (int i = 0; i < _animator.layerCount; i++)
Expand All @@ -1251,6 +1298,7 @@ public void Play(int hash)
/// <summary>
/// Plays a state.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Play(string name, int layer)
{
Play(Animator.StringToHash(name), layer);
Expand All @@ -1259,6 +1307,7 @@ public void Play(string name, int layer)
/// <summary>
/// Plays a state.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Play(int hash, int layer)
{
Play(hash, layer, 0f);
Expand All @@ -1267,6 +1316,7 @@ public void Play(int hash, int layer)
/// <summary>
/// Plays a state.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Play(string name, int layer, float normalizedTime)
{
Play(Animator.StringToHash(name), layer, normalizedTime);
Expand All @@ -1289,6 +1339,7 @@ public void Play(int hash, int layer, float normalizedTime)
/// <summary>
/// Plays a state.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PlayInFixedTime(string name, float fixedTime)
{
PlayInFixedTime(Animator.StringToHash(name), fixedTime);
Expand All @@ -1297,6 +1348,7 @@ public void PlayInFixedTime(string name, float fixedTime)
/// <summary>
/// Plays a state.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PlayInFixedTime(int hash, float fixedTime)
{
for (int i = 0; i < _animator.layerCount; i++)
Expand All @@ -1306,6 +1358,7 @@ public void PlayInFixedTime(int hash, float fixedTime)
/// <summary>
/// Plays a state.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void PlayInFixedTime(string name, int layer, float fixedTime)
{
PlayInFixedTime(Animator.StringToHash(name), layer, fixedTime);
Expand Down Expand Up @@ -1335,6 +1388,7 @@ public void PlayInFixedTime(int hash, int layer, float fixedTime)
/// <param name = "layer"></param>
/// <param name = "normalizedTimeOffset"></param>
/// <param name = "normalizedTransitionTime"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CrossFade(string stateName, float normalizedTransitionDuration, int layer, float normalizedTimeOffset = float.NegativeInfinity, float normalizedTransitionTime = 0.0f)
{
CrossFade(Animator.StringToHash(stateName), normalizedTransitionDuration, layer, normalizedTimeOffset, normalizedTransitionTime);
Expand Down Expand Up @@ -1367,6 +1421,7 @@ public void CrossFade(int hash, float normalizedTransitionDuration, int layer, f
/// <param name = "layer"></param>
/// <param name = "fixedTimeOffset"></param>
/// <param name = "normalizedTransitionTime"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void CrossFadeInFixedTime(string stateName, float fixedTransitionDuration, int layer, float fixedTimeOffset = 0.0f, float normalizedTransitionTime = 0.0f)
{
CrossFadeInFixedTime(Animator.StringToHash(stateName), fixedTransitionDuration, layer, fixedTimeOffset, normalizedTransitionTime);
Expand Down Expand Up @@ -1397,6 +1452,7 @@ public void CrossFadeInFixedTime(int hash, float fixedTransitionDuration, int la
/// Sets a trigger on the animator and sends it over the network.
/// </summary>
/// <param name = "hash"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetTrigger(int hash)
{
if (!_canSynchronizeAnimator)
Expand All @@ -1408,6 +1464,7 @@ public void SetTrigger(int hash)
/// Sets a trigger on the animator and sends it over the network.
/// </summary>
/// <param name = "hash"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetTrigger(string name)
{
SetTrigger(Animator.StringToHash(name));
Expand All @@ -1417,6 +1474,7 @@ public void SetTrigger(string name)
/// Resets a trigger on the animator and sends it over the network.
/// </summary>
/// <param name = "hash"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ResetTrigger(int hash)
{
UpdateTrigger(hash, false);
Expand All @@ -1426,6 +1484,7 @@ public void ResetTrigger(int hash)
/// Resets a trigger on the animator and sends it over the network.
/// </summary>
/// <param name = "hash"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ResetTrigger(string name)
{
ResetTrigger(Animator.StringToHash(name));
Expand Down
Loading