Fix up animator layer control references within the same animator

This change adjusts the layer indices for animator layer control state behaviors, assuming
that the reference is for a layer in the same animator. This partially addresses #67 for v1.0;
fully addressing this requires figuring out how to specify a reference to an arbitrary other Merge
Animator target.
This commit is contained in:
bd_ 2022-11-07 20:05:50 -08:00
parent bd9e3711ea
commit 4be0293d9d

View File

@ -28,6 +28,7 @@ using System.Linq;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using Object = UnityEngine.Object;
namespace net.fushizen.modular_avatar.core.editor
@ -47,6 +48,8 @@ namespace net.fushizen.modular_avatar.core.editor
private Dictionary<KeyValuePair<String, AnimatorStateMachine>, AnimatorStateMachine> _stateMachines =
new Dictionary<KeyValuePair<string, AnimatorStateMachine>, AnimatorStateMachine>();
private int controllerBaseLayer = 0;
public AnimatorCombiner()
{
_combined = Util.CreateAnimator();
@ -61,6 +64,8 @@ namespace net.fushizen.modular_avatar.core.editor
public void AddController(string basePath, AnimatorController controller, bool? writeDefaults)
{
controllerBaseLayer = _layers.Count;
foreach (var param in controller.parameters)
{
if (_parameters.TryGetValue(param.name, out var acp))
@ -136,6 +141,23 @@ namespace net.fushizen.modular_avatar.core.editor
asm = deepClone(layerStateMachine, (obj) => customClone(obj, basePath));
foreach (var state in asm.states)
{
foreach (var behavior in state.state.behaviours)
{
switch (behavior)
{
case VRCAnimatorLayerControl layerControl:
{
// TODO - need to figure out how to handle cross-layer references. For now this will handle
// intra-animator cases.
layerControl.layer += controllerBaseLayer;
break;
}
}
}
}
_stateMachines[cacheKey] = asm;
return asm;
}