Skip to content

Commit

Permalink
chore: deny ValueInfo<Object> to have Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Oct 4, 2024
1 parent 27d22ff commit aaf296f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
1 change: 0 additions & 1 deletion Editor/AnimatorParserV2/AnimatorParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public override void ModifyProperties(Component component, IEnumerable<string> p
foreach (var prop in properties)
{
_modifications.Add(component, prop, new VariableComponentPropModNode<float>(Modifier!), true);
_modifications.Add(component, prop, new VariableComponentPropModNode<Object>(Modifier!), true);
}
}
}
Expand Down
36 changes: 29 additions & 7 deletions Editor/AnimatorParserV2/PropModNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ public T ConstantValue

public T[]? PossibleValues => _possibleValues;

public static ValueInfo<T> Variable => default;
public static ValueInfo<T> Variable
{
get
{
if (default(T) == null) throw new InvalidOperationException("Variable type is not allowed with Object");
return default;
}
}

public ValueInfo(T value) => _possibleValues = new[] { value };

Expand Down Expand Up @@ -148,7 +155,7 @@ public static ValueInfo<T> ConstantInfoForOverriding<T, TLayer>(IEnumerable<TLay
where T : notnull
where TLayer : ILayer<T>
{
var canAdditive = typeof(T) == typeof(float);
var canAdditive = default(T) != null;
var allPossibleValues = new HashSet<T>();

foreach (var layer in layersReversed)
Expand All @@ -157,6 +164,7 @@ public static ValueInfo<T> ConstantInfoForOverriding<T, TLayer>(IEnumerable<TLay
{
case AnimatorWeightState.AlwaysOne:
case AnimatorWeightState.EitherZeroOrOne:
{
if (!(layer.Node.Value.PossibleValues is T[] otherValues)) return ValueInfo<T>.Variable;

switch (layer.BlendingMode)
Expand All @@ -181,10 +189,16 @@ public static ValueInfo<T> ConstantInfoForOverriding<T, TLayer>(IEnumerable<TLay
default:
throw new ArgumentOutOfRangeException();
}

}
break;
case AnimatorWeightState.Variable:
return ValueInfo<T>.Variable;
{
if (default(T) != null) return ValueInfo<T>.Variable; // float: variable
if (!(layer.Node.Value.PossibleValues is T[] otherValues))
throw new InvalidOperationException();
allPossibleValues.UnionWith(otherValues);
}
break;
default:
throw new ArgumentOutOfRangeException();
}
Expand Down Expand Up @@ -432,9 +446,17 @@ public BlendTreeNode(List<BlendTreeElement<T>> children,
public IReadOnlyList<BlendTreeElement<T>> Children => _children;
public override bool AppliedAlways => WeightSumIsOne && !_partial && _children.All(x => x.Node.AppliedAlways);

public override ValueInfo<T> Value => !WeightSumIsOne
? ValueInfo<T>.Variable
: NodeImplUtils.ConstantInfoForSideBySide(_children.Select(x => x.Node));
public override ValueInfo<T> Value
{
get
{
if (default(T) == null)
return NodeImplUtils.ConstantInfoForSideBySide(_children.Select(x => x.Node));
return !WeightSumIsOne
? ValueInfo<T>.Variable
: NodeImplUtils.ConstantInfoForSideBySide(_children.Select(x => x.Node));
}
}

public override IEnumerable<ObjectReference> ContextReferences =>
_children.SelectMany(x => x.Node.ContextReferences);
Expand Down

0 comments on commit aaf296f

Please sign in to comment.