MonoBehaviourProcessor: remove static WeavingFailed references

This commit is contained in:
vis2k 2021-08-20 20:58:29 +08:00
parent 64964fb169
commit b87096d5c9
2 changed files with 11 additions and 11 deletions

View File

@ -5,13 +5,13 @@ namespace Mirror.Weaver
// only shows warnings in case we use SyncVars etc. for MonoBehaviour.
static class MonoBehaviourProcessor
{
public static void Process(Logger Log, TypeDefinition td)
public static void Process(Logger Log, TypeDefinition td, ref bool WeavingFailed)
{
ProcessSyncVars(Log, td);
ProcessMethods(Log, td);
ProcessSyncVars(Log, td, ref WeavingFailed);
ProcessMethods(Log, td, ref WeavingFailed);
}
static void ProcessSyncVars(Logger Log, TypeDefinition td)
static void ProcessSyncVars(Logger Log, TypeDefinition td, ref bool WeavingFailed)
{
// find syncvars
foreach (FieldDefinition fd in td.Fields)
@ -19,18 +19,18 @@ static void ProcessSyncVars(Logger Log, TypeDefinition td)
if (fd.HasCustomAttribute<SyncVarAttribute>())
{
Log.Error($"SyncVar {fd.Name} must be inside a NetworkBehaviour. {td.Name} is not a NetworkBehaviour", fd);
Weaver.WeavingFailed = true;
WeavingFailed = true;
}
if (SyncObjectInitializer.ImplementsSyncObject(fd.FieldType))
{
Log.Error($"{fd.Name} is a SyncObject and must be inside a NetworkBehaviour. {td.Name} is not a NetworkBehaviour", fd);
Weaver.WeavingFailed = true;
WeavingFailed = true;
}
}
}
static void ProcessMethods(Logger Log, TypeDefinition td)
static void ProcessMethods(Logger Log, TypeDefinition td, ref bool WeavingFailed)
{
// find command and RPC functions
foreach (MethodDefinition md in td.Methods)
@ -38,17 +38,17 @@ static void ProcessMethods(Logger Log, TypeDefinition td)
if (md.HasCustomAttribute<CommandAttribute>())
{
Log.Error($"Command {md.Name} must be declared inside a NetworkBehaviour", md);
Weaver.WeavingFailed = true;
WeavingFailed = true;
}
if (md.HasCustomAttribute<ClientRpcAttribute>())
{
Log.Error($"ClientRpc {md.Name} must be declared inside a NetworkBehaviour", md);
Weaver.WeavingFailed = true;
WeavingFailed = true;
}
if (md.HasCustomAttribute<TargetRpcAttribute>())
{
Log.Error($"TargetRpc {md.Name} must be declared inside a NetworkBehaviour", md);
Weaver.WeavingFailed = true;
WeavingFailed = true;
}
}
}

View File

@ -35,7 +35,7 @@ static bool WeaveNetworkBehavior(TypeDefinition td)
if (!td.IsDerivedFrom<NetworkBehaviour>())
{
if (td.IsDerivedFrom<UnityEngine.MonoBehaviour>())
MonoBehaviourProcessor.Process(Log, td);
MonoBehaviourProcessor.Process(Log, td, ref WeavingFailed);
return false;
}