Skip to content

Instantly share code, notes, and snippets.

@mrvoorhe
Created March 19, 2020 18:53
Show Gist options
  • Save mrvoorhe/4711e93688968f4a8a13dda2344c4727 to your computer and use it in GitHub Desktop.
Save mrvoorhe/4711e93688968f4a8a13dda2344c4727 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Cecil;
using Mono.Linker;
using Mono.Linker.Steps;
using Unity.Cecil.Awesome;
namespace Unity.Linker.Steps.Resolution
{
public class ResolveFromMonoBehaviours : BaseResolveStep, IStep
{
private readonly AssemblyDefinition _assembly;
protected UnityLinkContext _context;
protected ResolveFromMonoBehaviours()
{
}
public ResolveFromMonoBehaviours(AssemblyDefinition assembly)
{
_assembly = assembly;
}
public UnityTracer Tracer => _context.Tracer;
public override void Process(LinkContext context)
{
_context = (UnityLinkContext)context;
foreach (var typeDefinition in _assembly.MainModule.AllDefinedTypes().Where(t => MonoBehaviorUtilities.IsMonoBehaviourOrScriptableObject(_context, t)))
{
ProcessType(typeDefinition);
}
}
protected void ProcessType(TypeDefinition typeDefinition)
{
using (Tracer.PushScoped(typeDefinition))
{
// Mark all types derived from MonoBehaviour
_context.Annotations.Mark(typeDefinition, new DependencyInfo(<What goes here?>);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment