modular-avatar/Runtime/ModularAvatarMergeAnimator.cs
bd_ 7086b35b3f
fix: play audio absolute paths in a relative controller break (#1555)
In MA 1.11.x, while we corrected relative play audio paths where possible,
we would leave them unchanged if no corresponding object was found. This
meant that we maintained compatibility with older assets that uses absolute
addressing for their Play Audio paths. This change restores that behavior.
2025-04-12 18:55:07 -07:00

106 lines
3.6 KiB
C#

/*
* MIT License
*
* Copyright (c) 2022 bd_
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#if MA_VRCSDK3_AVATARS
using System;
using nadena.dev.ndmf.animator;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
namespace nadena.dev.modular_avatar.core
{
public enum MergeAnimatorPathMode
{
Relative,
Absolute
}
public enum MergeAnimatorMode
{
Append,
Replace
}
[AddComponentMenu("Modular Avatar/MA Merge Animator")]
[HelpURL("https://modular-avatar.nadena.dev/docs/reference/merge-animator?lang=auto")]
public class ModularAvatarMergeAnimator : AvatarTagComponent, IVirtualizeAnimatorController
{
internal static Func<ModularAvatarMergeAnimator, object, string> GetMotionBasePathCallback =
(_, _) => "";
public RuntimeAnimatorController animator;
public VRCAvatarDescriptor.AnimLayerType layerType = VRCAvatarDescriptor.AnimLayerType.FX;
public bool deleteAttachedAnimator;
public MergeAnimatorPathMode pathMode = MergeAnimatorPathMode.Relative;
public bool matchAvatarWriteDefaults;
public AvatarObjectReference relativePathRoot = new AvatarObjectReference();
public int layerPriority = 0;
public MergeAnimatorMode mergeAnimatorMode = MergeAnimatorMode.Append;
internal bool _wasRelative;
public override void ResolveReferences()
{
// no-op
}
private void Reset()
{
// Init settings only when added or reset manually from the Inspector.
// Otherwise, some plugins that add this component may break in non-playmode builds.
if (RuntimeUtil.IsResetFromInspector())
{
InitSettings();
}
}
internal void InitSettings()
{
deleteAttachedAnimator = true;
}
RuntimeAnimatorController IVirtualizeAnimatorController.AnimatorController
{
get => animator;
set => animator = value;
}
string IVirtualizeAnimatorController.GetMotionBasePath(object ndmfBuildContext, bool clearPath)
{
var path = GetMotionBasePathCallback(this, ndmfBuildContext);
if (clearPath)
{
_wasRelative = _wasRelative || pathMode == MergeAnimatorPathMode.Relative;
pathMode = MergeAnimatorPathMode.Absolute;
}
return path;
}
object IVirtualizeAnimatorController.TargetControllerKey => layerType;
}
}
#endif