mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-29 18:55:06 +08:00
feat: add parameter introspection for automatic parameters (#970)
This commit is contained in:
parent
ead026a918
commit
d4683f99e3
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user