Skip to content

Commit

Permalink
fix: Misc code smells (#2094)
Browse files Browse the repository at this point in the history
* fix: code smell - condensed if statement

* fix: code smell - dont throw generic Exception
  • Loading branch information
uweeby committed Jul 14, 2020
1 parent 12827f6 commit e4cc85c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 26 deletions.
22 changes: 8 additions & 14 deletions Assets/Mirror/Components/Experimental/NetworkTransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,10 @@ public struct DataPoint
void FixedUpdate()
{
// if server then always sync to others.
if (isServer)
// let the clients know that this has moved
if (isServer && HasEitherMovedRotatedScaled())
{
// let the clients know that this has moved
if (HasEitherMovedRotatedScaled())
{
RpcMove(targetTransform.localPosition, targetTransform.localRotation, targetTransform.localScale);
}
RpcMove(targetTransform.localPosition, targetTransform.localRotation, targetTransform.localScale);
}

if (isClient)
Expand All @@ -127,15 +124,12 @@ void FixedUpdate()
// -> only if connectionToServer has been initialized yet too
if (IsOwnerWithClientAuthority)
{
if (!isServer)
if (!isServer && HasEitherMovedRotatedScaled())
{
if (HasEitherMovedRotatedScaled())
{
// serialize
// local position/rotation for VR support
// send to server
CmdClientToServerSync(targetTransform.localPosition, targetTransform.localRotation, targetTransform.localScale);
}
// serialize
// local position/rotation for VR support
// send to server
CmdClientToServerSync(targetTransform.localPosition, targetTransform.localRotation, targetTransform.localScale);
}
}
else if (goal.isValid)
Expand Down
5 changes: 2 additions & 3 deletions Assets/Mirror/Components/NetworkAnimator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ void HandleAnimMsg(int stateHash, float normalizedTime, int layerId, NetworkRead
// usually transitions will be triggered by parameters, if not, play anims directly.
// NOTE: this plays "animations", not transitions, so any transitions will be skipped.
// NOTE: there is no API to play a transition(?)
if (stateHash != 0)
if (stateHash != 0 && animator.enabled)
{
if (animator.enabled)
animator.Play(stateHash, layerId, normalizedTime);
animator.Play(stateHash, layerId, normalizedTime);
}

ReadParameters(reader);
Expand Down
10 changes: 4 additions & 6 deletions Assets/Mirror/Examples/Tanks/Scripts/TankGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,11 @@ void GameReadyCheck()
foreach (KeyValuePair<uint, NetworkIdentity> kvp in NetworkIdentity.spawned)
{
Tank comp = kvp.Value.GetComponent<Tank>();
if (comp != null)

//Add if new
if (comp != null && !players.Contains(comp))
{
if (!players.Contains(comp))
{
//Add if new
players.Add(comp);
}
players.Add(comp);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ void AssignSceneID()
// => throw an exception to cancel the build and let the user
// know how to fix it!
if (BuildPipeline.isBuildingPlayer)
throw new Exception("Scene " + gameObject.scene.path + " needs to be opened and resaved before building, because the scene object " + name + " has no valid sceneId yet.");
throw new InvalidOperationException("Scene " + gameObject.scene.path + " needs to be opened and resaved before building, because the scene object " + name + " has no valid sceneId yet.");

// if we generate the sceneId then we MUST be sure to set dirty
// in order to save the scene object properly. otherwise it
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Runtime/Transport/MultiplexTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override void ClientConnect(string address)
return;
}
}
throw new Exception("No transport suitable for this platform");
throw new ArgumentException("No transport suitable for this platform");
}

public override void ClientConnect(Uri uri)
Expand All @@ -101,7 +101,7 @@ public override void ClientConnect(Uri uri)
}
}
}
throw new Exception("No transport suitable for this platform");
throw new ArgumentException("No transport suitable for this platform");
}

public override bool ClientConnected()
Expand Down

0 comments on commit e4cc85c

Please sign in to comment.