From 95972329af32172a898df76268d94678ebf1cf16 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Tue, 9 Oct 2018 10:33:12 -0500 Subject: [PATCH] Simplify validation --- Mirror/Runtime/NetworkTransform.cs | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Mirror/Runtime/NetworkTransform.cs b/Mirror/Runtime/NetworkTransform.cs index d6d335e4e..ec83e00dc 100644 --- a/Mirror/Runtime/NetworkTransform.cs +++ b/Mirror/Runtime/NetworkTransform.cs @@ -240,17 +240,13 @@ void SerializeModeTransform(NetworkWriter writer) void VerifySerializeComponentExists() { - bool throwError = false; - Type componentMissing = null; - switch (transformSyncMode) { case TransformSyncMode.SyncCharacterController: m_CharacterController = m_CharacterController ?? GetComponent(); if (!m_CharacterController) { - throwError = true; - componentMissing = typeof(CharacterController); + throw new InvalidOperationException(string.Format("transformSyncMode set to {0} but no CharacterController component was found, did you call NetworkServer.Spawn on a prefab?", transformSyncMode)); } break; @@ -258,8 +254,7 @@ void VerifySerializeComponentExists() m_RigidBody2D = m_RigidBody2D ?? GetComponent(); if (!m_RigidBody2D) { - throwError = true; - componentMissing = typeof(Rigidbody2D); + throw new InvalidOperationException(string.Format("transformSyncMode set to {0} but no Rigidbody2D component was found, did you call NetworkServer.Spawn on a prefab?", transformSyncMode)); } break; @@ -267,16 +262,10 @@ void VerifySerializeComponentExists() m_RigidBody3D = m_RigidBody3D ?? GetComponent(); if (!m_RigidBody3D) { - throwError = true; - componentMissing = typeof(Rigidbody); + throw new InvalidOperationException(string.Format("transformSyncMode set to {0} but no Rigidbody component was found, did you call NetworkServer.Spawn on a prefab?", transformSyncMode)); } break; } - - if (throwError && componentMissing != null) - { - throw new InvalidOperationException(string.Format("transformSyncMode set to {0} but no {1} component was found, did you call NetworkServer.Spawn on a prefab?", transformSyncMode, componentMissing.Name)); - } } void SerializeMode3D(NetworkWriter writer)