mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-18 12:20:06 +08:00
76edc43aca
Add a new feature to generate animations for menu items automatically. Currently this only supports generating blend-tree based GameObject toggles.
68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Immutable;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using Object = System.Object;
|
|
|
|
namespace nadena.dev.modular_avatar.core
|
|
{
|
|
[RequireComponent(typeof(ModularAvatarMenuItem))]
|
|
[AddComponentMenu("Modular Avatar/MA Action Toggle Object")]
|
|
public class ActionToggleObject : AvatarTagComponent, SwitchedMenuAction
|
|
{
|
|
[Serializable]
|
|
public class ObjectEntry
|
|
{
|
|
public GameObject target;
|
|
public bool Active;
|
|
}
|
|
|
|
public List<ObjectEntry> Objects;
|
|
|
|
protected override void OnValidate()
|
|
{
|
|
base.OnValidate();
|
|
|
|
if (Objects == null)
|
|
{
|
|
Objects = new List<ObjectEntry>();
|
|
}
|
|
}
|
|
|
|
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetCurves()
|
|
{
|
|
return Objects.Select(obj =>
|
|
new KeyValuePair<MenuCurveBinding, AnimationCurve>(
|
|
new MenuCurveBinding(obj.target, typeof(GameObject), "m_IsActive"),
|
|
AnimationCurve.Constant(0, 1, obj.Active ? 1 : 0))
|
|
).ToImmutableDictionary();
|
|
}
|
|
|
|
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves(bool isDefault)
|
|
{
|
|
return Objects.Select(obj =>
|
|
{
|
|
bool active;
|
|
if (isDefault)
|
|
{
|
|
active = !obj.Active; // inactive state is the opposite of the default state
|
|
}
|
|
else
|
|
{
|
|
active = obj.target.activeSelf; // inactive state is the current state
|
|
}
|
|
|
|
return new KeyValuePair<MenuCurveBinding, AnimationCurve>(
|
|
new MenuCurveBinding(obj.target, typeof(GameObject), "m_IsActive"),
|
|
AnimationCurve.Constant(0, 1, active ? 1 : 0));
|
|
}
|
|
).ToImmutableDictionary();
|
|
}
|
|
|
|
public bool BindsParameter(TargetParameter parameter)
|
|
{
|
|
return parameter == TargetParameter.BaseParameter;
|
|
}
|
|
}
|
|
} |