feat: add parameter introspection for automatic parameters (#970)

This commit is contained in:
bd_ 2024-08-08 21:51:56 -07:00 committed by GitHub
parent ead026a918
commit d4683f99e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,6 +11,49 @@ using UnityEngine;
namespace nadena.dev.modular_avatar.core.editor
{
[ParameterProviderFor(typeof(ModularAvatarMenuItem))]
internal class MAMenuItemIntrospection : IParameterProvider
{
private readonly ModularAvatarMenuItem _component;
public MAMenuItemIntrospection(ModularAvatarMenuItem menuItem)
{
_component = menuItem;
}
public IEnumerable<ProvidedParameter> GetSuppliedParameters(ndmf.BuildContext context = null)
{
if (_component.Control == null || _component.GetComponent<ReactiveComponent>() == null) yield break;
var hidden = false;
var name = _component.Control?.parameter?.name;
if (string.IsNullOrWhiteSpace(name))
{
name = $"__MA/AutoParam/{_component.gameObject.name}${_component.GetInstanceID()}";
hidden = true;
}
var type = AnimatorControllerParameterType.Bool;
if (type != AnimatorControllerParameterType.Float &&
(_component.Control.value > 1.01 || _component.Control.value < -0.01))
type = AnimatorControllerParameterType.Int;
if (Mathf.Abs(Mathf.Round(_component.Control.value) - _component.Control.value) > 0.01f)
type = AnimatorControllerParameterType.Float;
yield return new ProvidedParameter(
name,
ParameterNamespace.Animator,
_component, PluginDefinition.Instance, type)
{
WantSynced = _component.isSynced,
IsHidden = hidden,
DefaultValue = _component.isDefault ? _component.Control.value : null
};
}
}
[ParameterProviderFor(typeof(ModularAvatarParameters))]
internal class MAParametersIntrospection : IParameterProvider
{