mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-05-02 17:29:01 +08:00
Implement VRCAnimatorPlayAudio handling logic (#899)
* feat: Implement VRCAnimatorPlayAudio handling logic (Quick & Dirty) * chore: Remove redundant PlayAudioHolder and debug logs
This commit is contained in:
parent
70aee65472
commit
90dfc1822c
@ -84,6 +84,9 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
|
|
||||||
private List<Action> _clipCommitActions = new List<Action>();
|
private List<Action> _clipCommitActions = new List<Action>();
|
||||||
private List<ClipHolder> _clips = new List<ClipHolder>();
|
private List<ClipHolder> _clips = new List<ClipHolder>();
|
||||||
|
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
|
||||||
|
private HashSet<VRCAnimatorPlayAudio> _playAudios = new HashSet<VRCAnimatorPlayAudio>();
|
||||||
|
#endif
|
||||||
|
|
||||||
private Dictionary<string, HashSet<ClipHolder>> _pathToClip = null;
|
private Dictionary<string, HashSet<ClipHolder>> _pathToClip = null;
|
||||||
|
|
||||||
@ -174,6 +177,16 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
|
|
||||||
if (processClip == null) processClip = (_) => { };
|
if (processClip == null) processClip = (_) => { };
|
||||||
|
|
||||||
|
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
|
||||||
|
foreach (var behavior in state.behaviours)
|
||||||
|
{
|
||||||
|
if (behavior is VRCAnimatorPlayAudio playAudio)
|
||||||
|
{
|
||||||
|
_playAudios.Add(playAudio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (state.motion == null) return;
|
if (state.motion == null) return;
|
||||||
|
|
||||||
var clipHolder = RegisterMotion(state.motion, state, processClip, _originalToHolder);
|
var clipHolder = RegisterMotion(state.motion, state, processClip, _originalToHolder);
|
||||||
@ -190,6 +203,16 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
|
||||||
|
internal void ForeachPlayAudio(Action<VRCAnimatorPlayAudio> processPlayAudio)
|
||||||
|
{
|
||||||
|
foreach (var playAudioHolder in _playAudios)
|
||||||
|
{
|
||||||
|
processPlayAudio(playAudioHolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of clips which touched the given _original_ path. This path is subject to basepath remapping,
|
/// Returns a list of clips which touched the given _original_ path. This path is subject to basepath remapping,
|
||||||
/// but not object movement remapping.
|
/// but not object movement remapping.
|
||||||
|
@ -496,7 +496,7 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
for (int i = 0; i < overrideBehaviors.Length; i++)
|
for (int i = 0; i < overrideBehaviors.Length; i++)
|
||||||
{
|
{
|
||||||
overrideBehaviors[i] = _deepClone.DoClone(overrideBehaviors[i]);
|
overrideBehaviors[i] = _deepClone.DoClone(overrideBehaviors[i]);
|
||||||
AdjustBehavior(overrideBehaviors[i]);
|
AdjustBehavior(overrideBehaviors[i], basePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
newLayer.SetOverrideBehaviours((AnimatorState)_cloneMap[state], overrideBehaviors);
|
newLayer.SetOverrideBehaviours((AnimatorState)_cloneMap[state], overrideBehaviors);
|
||||||
@ -578,7 +578,7 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
{
|
{
|
||||||
foreach (var behavior in state.behaviours)
|
foreach (var behavior in state.behaviours)
|
||||||
{
|
{
|
||||||
AdjustBehavior(behavior);
|
AdjustBehavior(behavior, basePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -586,7 +586,7 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
return asm;
|
return asm;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AdjustBehavior(StateMachineBehaviour behavior)
|
private void AdjustBehavior(StateMachineBehaviour behavior, string basePath)
|
||||||
{
|
{
|
||||||
#if MA_VRCSDK3_AVATARS
|
#if MA_VRCSDK3_AVATARS
|
||||||
switch (behavior)
|
switch (behavior)
|
||||||
@ -598,6 +598,16 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
layerControl.layer += _controllerBaseLayer;
|
layerControl.layer += _controllerBaseLayer;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
|
||||||
|
case VRCAnimatorPlayAudio playAudio:
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(playAudio.SourcePath) && !string.IsNullOrEmpty(basePath) && !playAudio.SourcePath.StartsWith(basePath))
|
||||||
|
{
|
||||||
|
playAudio.SourcePath = $"{basePath}/{playAudio.SourcePath}";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,9 @@ using nadena.dev.ndmf.util;
|
|||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
|
||||||
|
using VRC.SDK3.Avatars.Components;
|
||||||
|
#endif
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -274,6 +277,14 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
return newClip;
|
return newClip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
|
||||||
|
private VRCAnimatorPlayAudio ApplyMappingsToPlayAudio(VRCAnimatorPlayAudio audio)
|
||||||
|
{
|
||||||
|
audio.SourcePath = MapPath(audio.SourcePath, true);
|
||||||
|
return audio;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
internal void OnDeactivate(BuildContext context)
|
internal void OnDeactivate(BuildContext context)
|
||||||
{
|
{
|
||||||
Dictionary<AnimationClip, AnimationClip> clipCache = new Dictionary<AnimationClip, AnimationClip>();
|
Dictionary<AnimationClip, AnimationClip> clipCache = new Dictionary<AnimationClip, AnimationClip>();
|
||||||
@ -286,6 +297,13 @@ namespace nadena.dev.modular_avatar.animation
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#if MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER
|
||||||
|
_animationDatabase.ForeachPlayAudio(playAudio =>
|
||||||
|
{
|
||||||
|
ApplyMappingsToPlayAudio(playAudio);
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
foreach (var listener in context.AvatarRootObject.GetComponentsInChildren<IOnCommitObjectRenames>())
|
foreach (var listener in context.AvatarRootObject.GetComponentsInChildren<IOnCommitObjectRenames>())
|
||||||
{
|
{
|
||||||
listener.OnCommitObjectRenames(context, this);
|
listener.OnCommitObjectRenames(context, this);
|
||||||
|
@ -43,6 +43,11 @@
|
|||||||
"name": "com.vrchat.avatars",
|
"name": "com.vrchat.avatars",
|
||||||
"expression": "",
|
"expression": "",
|
||||||
"define": "MA_VRCSDK3_AVATARS"
|
"define": "MA_VRCSDK3_AVATARS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "com.vrchat.avatars",
|
||||||
|
"expression": "3.5.2",
|
||||||
|
"define": "MA_VRCSDK3_AVATARS_3_5_2_OR_NEWER"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"noEngineReferences": false
|
"noEngineReferences": false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user