Skip to content

Commit

Permalink
feat: NetworkAnimator warns if you use it incorrectly (#1424)
Browse files Browse the repository at this point in the history
* Added warnings to NetworkAnimator

* Updated ChangeLog

* pauls suggestions
  • Loading branch information
MrGadget authored and paulpach committed Jan 11, 2020
1 parent f858f4d commit c30e4a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
52 changes: 40 additions & 12 deletions Assets/Mirror/Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,31 @@ public void ResetTrigger(string triggerName)
/// <param name="hash">Hash id of trigger (from the Animator).</param>
public void SetTrigger(int hash)
{
if (hasAuthority && clientAuthority)
if (clientAuthority)
{
if (ClientScene.readyConnection != null)
if (!isClient)
{
CmdOnAnimationTriggerServerMessage(hash);
Debug.LogWarning("Tried to set animation in the server for a client-controlled animator");
return;
}

if (!hasAuthority)
{
Debug.LogWarning("Only the client with authority can set animations");
return;
}
return;
}

if (isServer && !clientAuthority)
if (ClientScene.readyConnection != null)
CmdOnAnimationTriggerServerMessage(hash);
}
else
{
if (!isServer)
{
Debug.LogWarning("Tried to set animation in the client for a server-controlled animator");
return;
}

RpcOnAnimationTriggerClientMessage(hash);
}
}
Expand All @@ -400,17 +414,31 @@ public void SetTrigger(int hash)
/// <param name="hash">Hash id of trigger (from the Animator).</param>
public void ResetTrigger(int hash)
{
if (hasAuthority && clientAuthority)
if (clientAuthority)
{
if (ClientScene.readyConnection != null)
if (!isClient)
{
CmdOnAnimationResetTriggerServerMessage(hash);
Debug.LogWarning("Tried to reset animation in the server for a client-controlled animator");
return;
}

if (!hasAuthority)
{
Debug.LogWarning("Only the client with authority can reset animations");
return;
}
return;
}

if (isServer && !clientAuthority)
if (ClientScene.readyConnection != null)
CmdOnAnimationResetTriggerServerMessage(hash);
}
else
{
if (!isServer)
{
Debug.LogWarning("Tried to reset animation in the client for a server-controlled animator");
return;
}

RpcOnAnimationResetTriggerClientMessage(hash);
}
}
Expand Down
2 changes: 1 addition & 1 deletion doc/General/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Change Log

## Version 7.x.x - In Progress
- Added: NetworkAnimator now has a ResetTrigger function
- Added: NetworkAnimator now has a ResetTrigger function and server / client authority warnings
- Fixed: NetworkTransform and NetworkAnimator now uses NetworkWriterPool
- Fixed: NetworkTransform and NetworkAnimator now respect `hasAuthority` for client owned objects
- Fixed: NetworkTransform will now correctly teleport if time / distance are too large
Expand Down

0 comments on commit c30e4a9

Please sign in to comment.