Skip to content

Commit

Permalink
Call hooks in correct order.
Browse files Browse the repository at this point in the history
  • Loading branch information
Banane9 committed Feb 16, 2024
1 parent 05ef3a5 commit 12d4372
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions MonkeyLoader.Unity.Integration/UnityHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ internal sealed class UnityHooks : Monkey<UnityHooks>
{
public override string Name { get; } = "Unity Hooks";

private static IEnumerable<IUnityMonkeyInternal> UnityMonkeys
=> Mod.Loader.Monkeys.SelectCastable<IMonkey, IUnityMonkeyInternal>();
private static IUnityMonkeyInternal[] UnityMonkeys
{
get
{
var monkeys = Mod.Loader.Monkeys
.SelectCastable<IMonkey, IUnityMonkeyInternal>()
.ToArray();

Array.Sort(monkeys, Monkey.AscendingComparer);

return monkeys;
}
}

protected override IEnumerable<IFeaturePatch> GetFeaturePatches() => Enumerable.Empty<IFeaturePatch>();

Expand All @@ -32,14 +43,14 @@ private void SceneManager_sceneLoaded(Scene scene, LoadSceneMode sceneMode)
{
Info(() => "First Scene Loaded! Executing OnFirstSceneReady hooks on UnityMonkeys!");

var unityMonkeys = UnityMonkeys.ToArray();
var unityMonkeys = UnityMonkeys;
Logger.Trace(() => "Running FirstSceneReady hooks in this order:");
Logger.Trace(unityMonkeys.Select(uM => new Func<object>(() => $"{uM.Mod.Title}/{uM.Name}")));

SceneManager.sceneLoaded -= SceneManager_sceneLoaded;
var sw = Stopwatch.StartNew();

foreach (var unityMonkey in UnityMonkeys)
foreach (var unityMonkey in unityMonkeys)
unityMonkey.FirstSceneReady(scene);

Info(() => $"Done executing OnFirstSceneReady hooks on UnityMonkeys in {sw.ElapsedMilliseconds}ms!");
Expand Down

0 comments on commit 12d4372

Please sign in to comment.