Created
November 28, 2017 17:23
-
-
Save ByronMayne/b8f2cebe2ca2b89416da3d76c2486dbf to your computer and use it in GitHub Desktop.
This is an example weaver componet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Mono.Cecil; | |
using UnityEngine; | |
using Mono.Cecil.Cil; | |
namespace Weaver | |
{ | |
// Inherit WeaverComponent to get callbacks and to show up as a componet in our ScriptableObject settings. | |
public class ServerCommandComponent : WeaverComponent | |
{ | |
// Used for logging the name really does not matter. | |
public override string addinName | |
{ | |
get | |
{ | |
return "Server Command"; | |
} | |
} | |
// Defines which type of callbacks you want. Used as an optimization | |
public override DefinitionType effectedDefintions | |
{ | |
get | |
{ | |
return DefinitionType.Method; | |
} | |
} | |
// Invoked for every method in each assembly that is listed in WeavedAssemblies in settings. | |
public override void VisitMethod(MethodDefinition methodDefinition) | |
{ | |
CustomAttribute serverCommandAttribute = methodDefinition.GetCustomAttribute<ServerCommandAttribute>(); | |
if (serverCommandAttribute == null) | |
{ | |
// Our method does not have the attribute so we skip it. | |
return; | |
} | |
// Do the IL Injection. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment