Skip to content

Commit 0dae5b4

Browse files
committed
refactor: Only warned about Unity reflection methods for development builds
1 parent bf4d64c commit 0dae5b4

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

MLAPI/Core/NetworkedBehaviour.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,21 +174,25 @@ internal void InternalNetworkStart()
174174

175175
private void WarnUnityReflectionMethodUse()
176176
{
177-
MethodInfo[] methods = GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
178-
for (int i = 0; i < methods.Length; i++)
177+
if (Debug.isDebugBuild)
179178
{
180-
if (methods[i].Name == "OnDestroy")
181-
{
182-
throw new Exception("The method \"OnDestroy\" is not allowed to be defined in classes that inherit NetworkedBehaviour. Please override the \"OnDestroyed\" method instead");
183-
}
184-
else if (methods[i].Name == "OnDisable")
185-
{
186-
throw new Exception("The method \"OnDisable\" is not allowed to be defined in classes that inherit NetworkedBehaviour. Please override the \"OnDisabled\" method instead");
187-
}
188-
else if (methods[i].Name == "OnEnable")
179+
MethodInfo[] methods = GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
180+
181+
for (int i = 0; i < methods.Length; i++)
189182
{
190-
throw new Exception("The method \"OnEnable\" is not allowed to be defined in classes that inherit NetworkedBehaviour. Please override the \"OnEnable\" method instead");
191-
}
183+
if (methods[i].Name == "OnDestroy")
184+
{
185+
throw new Exception("The method \"OnDestroy\" is not allowed to be defined in classes that inherit NetworkedBehaviour. Please override the \"OnDestroyed\" method instead");
186+
}
187+
else if (methods[i].Name == "OnDisable")
188+
{
189+
throw new Exception("The method \"OnDisable\" is not allowed to be defined in classes that inherit NetworkedBehaviour. Please override the \"OnDisabled\" method instead");
190+
}
191+
else if (methods[i].Name == "OnEnable")
192+
{
193+
throw new Exception("The method \"OnEnable\" is not allowed to be defined in classes that inherit NetworkedBehaviour. Please override the \"OnEnable\" method instead");
194+
}
195+
}
192196
}
193197
}
194198

0 commit comments

Comments
 (0)