Table of Contents

Consider this case:
You have a piece of code that should be executed after some SubModule, e.g. StoryModeSubModule, but you don't want to add StoryMode as a DependedModule.
This is not supported out-of-the-box, but ButterLib provides one possible solution.

protected override void OnSubModuleLoad()
 {
    base.OnSubModuleLoad();

    // You first call Register() so the SubModule will be tracked by ButterLib
    DelayedSubModuleManager.Register<StoryModeSubModule>();
    // You subscribe to the module's method call.
    // In this case, we do something after StoryModeSubModule.OnSubModuleLoad
    // is executed.
    DelayedSubModuleManager.Subscribe<StoryModeSubModule, SubModule>(
        nameof(OnSubModuleLoad), SubscriptionType.AfterMethod, (s, e) =>
        {
            // StoryModeSubModule does not implement OnSubModuleLoad(),
            // so we can only catch the base virtual method call.
            if (e.IsBase)
                return;

            // SOME CODE
        });
}
protected override void OnBeforeInitialModuleScreenSetAsRoot()
 {
    base.OnBeforeInitialModuleScreenSetAsRoot();

    DelayedSubModuleManager.Register<GauntletUISubModule>();
    DelayedSubModuleManager.Subscribe<GauntletUISubModule, SubModule>(
        nameof(OnBeforeInitialModuleScreenSetAsRoot), SubscriptionType.AfterMethod, (s, e) =>
        {
            // GauntletUISubModule overrides OnBeforeInitialModuleScreenSetAsRoot, so we can
            // catch the override method call.
            if (!e.IsBase)
                return;

            // SOME CODE
        });
}

Note:


This page was last modified at 10/13/2020 15:35:52 +03:00 (UTC).

Commit Message
Author:    aragas
Commit:    f25a1264d096d9287b99c5d2b04bd6032ad81546
Actually fixed the shit