modular-avatar/Editor/ReactiveObjects/AnimationGeneration/ReactionRule.cs
bd_ 30cafb21e4
fix: incorrect handling of shape key deletion (#1258)
This change reworks delete handling to be more consistent with other properties,
by treating it as a virtual property (`deletedShape.{blendshapeName}`) instead of
a weird additional field of blendshape keys. This then fixes a number of issues
(e.g. broken preview for delete keys).

Fixes: #1253
2024-10-03 20:16:53 -07:00

63 lines
1.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace nadena.dev.modular_avatar.core.editor
{
internal class ReactionRule
{
public ReactionRule(TargetProp key, float value)
: this(key, (object)value) { }
public ReactionRule(TargetProp key, Object value)
: this(key, (object)value) { }
private ReactionRule(TargetProp key, object value)
{
TargetProp = key;
ControllingConditions = new();
Value = value;
}
public TargetProp TargetProp;
public object Value;
public Component ControllingObject;
public List<ControlCondition> ControllingConditions;
public bool InitiallyActive =>
((ControllingConditions.Count == 0) || ControllingConditions.All(c => c.InitiallyActive)) ^ Inverted;
public bool Inverted;
public bool IsConstant => ControllingConditions.Count == 0
|| ControllingConditions.All(c => c.IsConstant)
|| ControllingConditions.Any(c => c.IsConstant && !c.InitiallyActive);
public bool IsConstantActive => IsConstant && InitiallyActive ^ Inverted;
public override string ToString()
{
return $"AGK: {TargetProp}={Value}";
}
public bool TryMerge(ReactionRule other)
{
if (!TargetProp.Equals(other.TargetProp)) return false;
// Value checks
if (Value == other.Value) { /* objects match */ }
else if (Value is float a && other.Value is float b)
{
if (Mathf.Abs(a - b) > 0.001f) return false;
}
else return false;
if (!ControllingConditions.SequenceEqual(other.ControllingConditions)) return false;
return true;
}
}
}