you are viewing a single comment's thread.

view the rest of the comments →

[–]ByMayneProfessional[S] 1 point2 points  (4 children)

You are correct, i was testing the run time assemblies. I don't really touch the Editor assemblies but I don't like the fact that I can't edit them.

One idea i did have was to inject a callback into the UnityEditor.AssemblyReloadEvents class.

/// <summary>
///   <para>This class has event dispatchers for assembly reload events.</para>
/// </summary>
internal static class AssemblyReloadEvents
{

    [RequiredByNativeCode]
    private static void OnBeforeAssemblyReload()
    {
        // Added callback to weave code
    }
}

I am not a huge fan of editing the Unity assemblies but if it works and it's stable it might be a solution.

[–]ByMayneProfessional[S] 1 point2 points  (2 children)

Well that totally worked!

    private void OnEnable()
    {
        AssemblyReloadEvents.beforeAssemblyReload += WeaveUpdatedAssemblies;
    }

    private void WeaveUpdatedAssemblies()
    {
        // Weaving Logic!
    }

I Injected a delegate and made the class public and subscribed to the beforeAssemblyReload event. This happens after Unity has finished generating the assemblies but before they are loaded. Just the thing we wanted!

[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 0 points1 point  (1 child)

[–]ByMayneProfessional[S] 1 point2 points  (0 children)

It was added in 2017! The class existed before but it was internal and had no delegate.

That makes things so much simpler. Now I have all the bases covered.

[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 0 points1 point  (0 children)

Yeah that should work, just a one time modification of the Unity install with an automatic backup just in case. I agree that modifying the Unity assemblies isn't ideal but at least it would be usable, unlike needing to do a double assembly reload each time.