2024-10-20 09:58:41 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
|
|
|
|
#region
|
2024-02-21 19:40:31 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2024-02-12 13:59:39 +08:00
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using nadena.dev.ndmf;
|
2024-02-21 19:40:31 +08:00
|
|
|
|
using UnityEditor.Animations;
|
2024-02-12 13:59:39 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2024-02-21 19:40:31 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2024-02-12 13:59:39 +08:00
|
|
|
|
namespace nadena.dev.modular_avatar.core.editor
|
|
|
|
|
{
|
|
|
|
|
internal class ApplyAnimatorDefaultValuesPass : Pass<ApplyAnimatorDefaultValuesPass>
|
|
|
|
|
{
|
|
|
|
|
protected override void Execute(ndmf.BuildContext context)
|
|
|
|
|
{
|
2024-03-05 16:20:43 +08:00
|
|
|
|
if (!context.AvatarDescriptor) return;
|
|
|
|
|
|
2024-02-21 19:40:31 +08:00
|
|
|
|
var values = context.GetState<DefaultValues>()?.InitialValueOverrides
|
2024-02-12 13:59:39 +08:00
|
|
|
|
?? ImmutableDictionary<string, float>.Empty;
|
|
|
|
|
|
|
|
|
|
foreach (var layer in context.AvatarDescriptor.baseAnimationLayers
|
|
|
|
|
.Concat(context.AvatarDescriptor.specialAnimationLayers))
|
|
|
|
|
{
|
|
|
|
|
if (layer.isDefault || layer.animatorController == null) continue;
|
|
|
|
|
|
|
|
|
|
// We should have converted anything that's not an AnimationController by now
|
2024-02-21 19:40:31 +08:00
|
|
|
|
var controller = layer.animatorController as AnimatorController;
|
2024-02-12 13:59:39 +08:00
|
|
|
|
if (controller == null || !context.IsTemporaryAsset(controller))
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("Leaked unexpected controller: " + layer.animatorController + " (type " + layer.animatorController?.GetType() + ")");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var parameters = controller.parameters;
|
|
|
|
|
for (int i = 0; i < parameters.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!values.TryGetValue(parameters[i].name, out var defaultValue)) continue;
|
|
|
|
|
|
|
|
|
|
switch (parameters[i].type)
|
|
|
|
|
{
|
|
|
|
|
case AnimatorControllerParameterType.Bool:
|
2024-09-18 10:47:56 +08:00
|
|
|
|
parameters[i].defaultBool = defaultValue != 0.0f;
|
2024-02-12 13:59:39 +08:00
|
|
|
|
break;
|
|
|
|
|
case AnimatorControllerParameterType.Int:
|
|
|
|
|
parameters[i].defaultInt = Mathf.RoundToInt(defaultValue);
|
|
|
|
|
break;
|
|
|
|
|
case AnimatorControllerParameterType.Float:
|
|
|
|
|
parameters[i].defaultFloat = defaultValue;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
continue; // unhandled type, e.g. trigger
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
controller.parameters = parameters;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-20 09:58:41 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|