From 4be0293d9dfc60c1b92d850607a5f3c01aec3b31 Mon Sep 17 00:00:00 2001 From: bd_ Date: Mon, 7 Nov 2022 20:05:50 -0800 Subject: [PATCH] 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. --- .../Editor/AnimatorMerger.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Packages/net.fushizen.modular-avatar/Editor/AnimatorMerger.cs b/Packages/net.fushizen.modular-avatar/Editor/AnimatorMerger.cs index 9db2fdba..c1289bb5 100644 --- a/Packages/net.fushizen.modular-avatar/Editor/AnimatorMerger.cs +++ b/Packages/net.fushizen.modular-avatar/Editor/AnimatorMerger.cs @@ -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, AnimatorStateMachine> _stateMachines = new Dictionary, 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; }