Make sure State and SSM names don't contain a period '.':
- If the name of a state contains a period ".", it can cause the animator to misbehave, so sanitize it. - Transitions would not work properly during the runtime execution of the animator. - Apparently this is because sub state machines internally use the dot as a separator. - Sanitize the name so that menu state names such as "J. Inner" don't mess things up.
This commit is contained in:
@@ -159,7 +159,7 @@ namespace AnimatorAsCode.V1
|
|||||||
/// 🔺 If the name is already used, a number will be appended at the end.
|
/// 🔺 If the name is already used, a number will be appended at the end.
|
||||||
public AacFlStateMachine NewSubStateMachine(string name, int x, int y)
|
public AacFlStateMachine NewSubStateMachine(string name, int x, int y)
|
||||||
{
|
{
|
||||||
var stateMachine = AacInternals.NoUndo(Machine, () => Machine.AddStateMachine(EnsureNameIsDeduplicated(name), GridPosition(x, y)));
|
var stateMachine = AacInternals.NoUndo(Machine, () => Machine.AddStateMachine(SanitizeAndEnsureNameIsDeduplicated(name), GridPosition(x, y)));
|
||||||
var aacMachine = new AacFlStateMachine(stateMachine, _emptyClip, _backingAnimator, DefaultsProvider, AnimatorRoot, this);
|
var aacMachine = new AacFlStateMachine(stateMachine, _emptyClip, _backingAnimator, DefaultsProvider, AnimatorRoot, this);
|
||||||
_defaultsProvider.ConfigureStateMachine(stateMachine);
|
_defaultsProvider.ConfigureStateMachine(stateMachine);
|
||||||
_childNodes.Add(aacMachine);
|
_childNodes.Add(aacMachine);
|
||||||
@@ -202,7 +202,7 @@ namespace AnimatorAsCode.V1
|
|||||||
/// 🔺 If the name is already used, a number will be appended at the end.
|
/// 🔺 If the name is already used, a number will be appended at the end.
|
||||||
public AacFlState NewState(string name, int x, int y)
|
public AacFlState NewState(string name, int x, int y)
|
||||||
{
|
{
|
||||||
var state = AacInternals.NoUndo(Machine, () => Machine.AddState(EnsureNameIsDeduplicated(name), GridPosition(x, y)));
|
var state = AacInternals.NoUndo(Machine, () => Machine.AddState(SanitizeAndEnsureNameIsDeduplicated(name), GridPosition(x, y)));
|
||||||
DefaultsProvider.ConfigureState(state, _emptyClip);
|
DefaultsProvider.ConfigureState(state, _emptyClip);
|
||||||
var aacState = new AacFlState(state, this, DefaultsProvider, AnimatorRoot);
|
var aacState = new AacFlState(state, this, DefaultsProvider, AnimatorRoot);
|
||||||
_childNodes.Add(aacState);
|
_childNodes.Add(aacState);
|
||||||
@@ -210,8 +210,10 @@ namespace AnimatorAsCode.V1
|
|||||||
return aacState;
|
return aacState;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string EnsureNameIsDeduplicated(string name)
|
private string SanitizeAndEnsureNameIsDeduplicated(string name)
|
||||||
{
|
{
|
||||||
|
name = SanitizeName(name);
|
||||||
|
|
||||||
var suffix = 0;
|
var suffix = 0;
|
||||||
var stateName = name;
|
var stateName = name;
|
||||||
while (_stateNames.Contains(stateName))
|
while (_stateNames.Contains(stateName))
|
||||||
@@ -223,6 +225,17 @@ namespace AnimatorAsCode.V1
|
|||||||
return stateName;
|
return stateName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string SanitizeName(string name)
|
||||||
|
{
|
||||||
|
// If the name contains a period ".", it can cause the animator to misbehave
|
||||||
|
// as in, transitions will not work properly.
|
||||||
|
// incredible but true
|
||||||
|
// Apparently this is because substates use the dot as a separator or something
|
||||||
|
// Sanitize the name so that menu state names such as "J. Inner" don't mess things up
|
||||||
|
// return Regex.Replace(controlName, "[^A-Za-z0-9]", "");
|
||||||
|
return name.Replace(".", "_");
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a transition from Any to the `destination` state.
|
/// Create a transition from Any to the `destination` state.
|
||||||
public AacFlTransition AnyTransitionsTo(AacFlState destination)
|
public AacFlTransition AnyTransitionsTo(AacFlState destination)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user