Skip to content

Commit d684643

Browse files
update
Adding the ability to select server or owner authority mode via the inspector view.
1 parent 29913e9 commit d684643

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,35 @@ internal class TransitionStateinfo
200200
public int TransitionIndex;
201201
}
202202

203+
/// <summary>
204+
/// Determines if the server or client owner pushes animation state updates.
205+
/// </summary>
206+
public enum AuthorityModes
207+
{
208+
/// <summary>
209+
/// Server pushes animator state updates.
210+
/// </summary>
211+
Server,
212+
/// <summary>
213+
/// Client owner pushes animator state updates.
214+
/// </summary>
215+
Owner,
216+
}
217+
218+
219+
/// <summary>
220+
/// Determines whether this <see cref="NetworkAnimator"/> instance will have state updates pushed by the server or the client owner.
221+
/// <see cref="AuthorityModes"/>
222+
/// </summary>
223+
#if MULTIPLAYER_SERVICES_SDK_INSTALLED
224+
[Tooltip("Selects who has authority (sends state updates) over the <see cref="NetworkAnimator"/> instance. When the network topology is set to distributed authority, this always defaults to owner authority. If server (the default), then only server-side adjustments to the " +
225+
"<see cref="NetworkAnimator"/> instance will be synchronized with clients. If owner (or client), then only the owner-side adjustments to the <see cref="NetworkAnimator"/> instance will be synchronized with both the server and other clients.")]
226+
#else
227+
[Tooltip("Selects who has authority (sends state updates) over the <see cref=\"NetworkAnimator\"/> instance. If server (the default), then only server-side adjustments to the <see cref=\"NetworkAnimator\"/> instance will be synchronized with clients. If owner (or client), " +
228+
"then only the owner-side adjustments to the <see cref=\"NetworkAnimator\"/> instance will be synchronized with both the server and other clients.")]
229+
#endif
230+
public AuthorityModes AuthorityMode;
231+
203232
/// <summary>
204233
/// Used to build the destination state to transition info table
205234
/// </summary>
@@ -484,6 +513,9 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
484513

485514
[SerializeField] private Animator m_Animator;
486515

516+
/// <summary>
517+
/// The <see cref="Animator"/> associated with this <see cref="NetworkAnimator"/> instance.
518+
/// </summary>
487519
public Animator Animator
488520
{
489521
get { return m_Animator; }
@@ -493,21 +525,27 @@ public Animator Animator
493525
}
494526
}
495527

496-
internal bool IsServerAuthoritative()
528+
/// <summary>
529+
/// Determines whether the <see cref="NetworkAnimator"/> is <see cref="AuthorityModes.Server"/> or <see cref="AuthorityModes.Owner"/> based on the <see cref="AuthorityMode"/> field.
530+
/// Optionally, you can still derive from <see cref="NetworkAnimator"/> and override the <see cref="OnIsServerAuthoritative"/> method.
531+
/// </summary>
532+
/// <returns><see cref="true"/> or <see cref="false"/></returns>
533+
public bool IsServerAuthoritative()
497534
{
498535
return OnIsServerAuthoritative();
499536
}
500537

501538
/// <summary>
502-
/// Override this method and return false to switch to owner authoritative mode.
539+
/// Override this method and return false to switch to owner authoritative mode.<br />
540+
/// Alternately, you can update the <see cref="AuthorityMode"/> field within the inspector view to select the authority mode.
503541
/// </summary>
504542
/// <remarks>
505543
/// When using a distributed authority network topology, this will default to
506544
/// owner authoritative.
507545
/// </remarks>
508546
protected virtual bool OnIsServerAuthoritative()
509547
{
510-
return NetworkManager ? !NetworkManager.DistributedAuthorityMode : true;
548+
return NetworkManager && NetworkManager.DistributedAuthorityMode ? true : AuthorityMode == AuthorityModes.Server;
511549
}
512550

513551
private int[] m_TransitionHash;

0 commit comments

Comments
 (0)