feat: control groups now use default-to-off, no override support for now

This commit is contained in:
bd_ 2023-04-30 20:08:31 +09:00
parent cae4622bfc
commit 93a0171940
4 changed files with 27 additions and 25 deletions

View File

@ -110,7 +110,7 @@ namespace nadena.dev.modular_avatar.core.editor
AnimationClip clip = new AnimationClip();
foreach (var renderer in avatar.GetComponentsInChildren<SkinnedMeshRenderer>())
{
if (!renderer.sharedMesh) continue;
if (!renderer.sharedMesh) continue;
int nShapes = renderer.sharedMesh.blendShapeCount;
for (int i = 0; i < nShapes; i++)
{
@ -222,8 +222,8 @@ namespace nadena.dev.modular_avatar.core.editor
expParams.parameters?.ToList() ?? new List<VRCExpressionParameters.Parameter>();
List<BlendTree> blendTrees = new List<BlendTree>();
Dictionary<ActionController, List<ModularAvatarMenuItem>> groupedItems =
new Dictionary<ActionController, List<ModularAvatarMenuItem>>();
Dictionary<Component, List<ModularAvatarMenuItem>> groupedItems =
new Dictionary<Component, List<ModularAvatarMenuItem>>();
foreach (var item in items)
{
@ -274,7 +274,21 @@ namespace nadena.dev.modular_avatar.core.editor
group.Insert(0, null);
}
bool isSaved = kvp.Key.isSavedProp, isSynced = kvp.Key.isSyncedProp;
bool isSaved, isSynced;
if (kvp.Key is ControlGroup cg_)
{
isSaved = cg_.isSaved;
isSynced = cg_.isSynced;
}
else if (kvp.Key is ModularAvatarMenuItem menuItem)
{
isSaved = menuItem.isSaved;
isSynced = menuItem.isSynced;
}
else
{
throw new Exception("Unknown type " + kvp.Key.GetType());
}
expParameters.Add(new VRCExpressionParameters.Parameter()
{
@ -341,7 +355,7 @@ namespace nadena.dev.modular_avatar.core.editor
void MergeCurves(
IDictionary<MenuCurveBinding, (Component, AnimationCurve)> curves,
ActionController controller,
Component controller,
Func<SwitchedMenuAction, IDictionary<MenuCurveBinding, AnimationCurve>> getCurves,
bool ignoreDuplicates
)
@ -382,7 +396,7 @@ namespace nadena.dev.modular_avatar.core.editor
private List<Motion> GenerateMotions(
List<ModularAvatarMenuItem> items,
Dictionary<MenuCurveBinding, Component> bindings,
ActionController controller
Component controller
)
{
Dictionary<MenuCurveBinding, Component> newBindings = new Dictionary<MenuCurveBinding, Component>();
@ -397,7 +411,7 @@ namespace nadena.dev.modular_avatar.core.editor
foreach (var item in items)
{
MergeCurves(inactiveCurves, item, a => a.GetInactiveCurves(false), true);
MergeCurves(inactiveCurves, item, a => a.GetInactiveCurves(), true);
}
var inactiveMotion = CurvesToMotion(inactiveCurves);

View File

@ -39,7 +39,7 @@ namespace nadena.dev.modular_avatar.core
).ToImmutableDictionary();
}
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves(bool isDefault)
public ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves()
{
var builder = ImmutableDictionary<MenuCurveBinding, AnimationCurve>.Empty.ToBuilder();
@ -49,19 +49,9 @@ namespace nadena.dev.modular_avatar.core
if (target == null) continue;
bool active;
if (isDefault)
{
active = !obj.Active; // inactive state is the opposite of the default state
}
else
{
active = target.activeSelf; // inactive state is the current state
}
builder.Add(
new MenuCurveBinding(target, typeof(GameObject), "m_IsActive"),
AnimationCurve.Constant(0, 1, active ? 1 : 0)
AnimationCurve.Constant(0, 1, 0)
);
}

View File

@ -3,14 +3,11 @@
namespace nadena.dev.modular_avatar.core
{
[AddComponentMenu("Modular Avatar/MA Control Group")]
public class ControlGroup : ActionController
public class ControlGroup : AvatarTagComponent
{
public bool isSynced = true;
public bool isSaved = true;
public ModularAvatarMenuItem defaultValue;
internal override bool isSyncedProp => isSynced;
internal override bool isSavedProp => isSaved;
}
}

View File

@ -24,10 +24,11 @@ namespace nadena.dev.modular_avatar.core
/// <summary>
/// Returns the curves applied when this action is inactive (and no other actions override).
/// In general, this should depend only on the path and state of the target objects, and not on the
/// configuration of the action itself (apart from target selection).
/// </summary>
/// <param name="isDefault">True if this action is part of the default toggle option.</param>
/// <returns></returns>
ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves(bool isDefault);
ImmutableDictionary<MenuCurveBinding, AnimationCurve> GetInactiveCurves();
}
public enum TargetParameter