Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Animators updating all fields while they are enabled but not playing #10

Merged
merged 1 commit into from
Jan 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions CommunityBugFixCollection/PauseAnimatorUpdates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using FrooxEngine;
using HarmonyLib;
using MonkeyLoader.Resonite;
using System;
using System.Collections.Generic;
using System.Text;

namespace CommunityBugFixCollection
{
[HarmonyPatchCategory(nameof(PauseAnimatorUpdates))]
[HarmonyPatch(typeof(Animator), nameof(Animator.OnCommonUpdate))]
internal sealed class PauseAnimatorUpdates : ResoniteMonkey<PauseAnimatorUpdates>
{
public override bool CanBeDisabled => true;

private static bool Prefix(Animator __instance)
{
__instance._playback.ClipLength = (__instance.Clip.Asset?.Data?.GlobalDuration).GetValueOrDefault();

if (!__instance._fieldMappersValid)
__instance.GenerateFieldMappers();

if (__instance.IsPlaying)
{
var position = __instance.Position;

foreach (var fieldMapper in __instance._fieldMappers)
fieldMapper.Set(position);
}

return false;
}

private static bool Prepare() => Enabled;
}
}
Loading