FACS01-01 faad9b17ce
AnimatorController Child State Machine Recovery (#1389)
* first draft

* change requests

* actually working draft

* duplicated method

* use more the new method

* - put StateContext class on a separate file
- new BidirectionalDictionary<T1,T2> class
- other tweaks

* - put StateMachineContext class on a separate file
- move all asset creations into VirtualAnimationFactory class
- added extension method GetName() to IStateConstant
- other tweaks

* Apply suggestions from code review

Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>

* apply requested changes

* Apply suggestions from code review

Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>

* reorder methods

* Update Source/AssetRipper.Processing/AnimatorControllers/AnimatorStateContext.cs

Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>

* apply requested changes

* IndexedState to StateData[]

* Update Source/AssetRipper.Processing/AnimatorControllers/AnimatorStateContext.cs

Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>

* apply requested changes

* Apply suggestions from code review

Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>

* a lot of restructuring and comments

* statemachine parenting finished

* simplify CreateDefaultAnimatorState

* small tweaks

---------

Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>
2025-04-09 13:18:42 -07:00

65 lines
1.8 KiB
C#

using AssetRipper.Assets.Generics;
using AssetRipper.SourceGenerated.Subclasses.BlendTreeConstant;
using AssetRipper.SourceGenerated.Subclasses.StateConstant;
namespace AssetRipper.SourceGenerated.Extensions
{
public static class StateConstantExtensions
{
public static bool IsBlendTree(this IStateConstant stateConstant)
{
if (stateConstant.BlendTreeConstantArray.Count == 0)
{
return false;
}
return stateConstant.GetBlendTree().NodeArray.Count > 1;
}
public static IBlendTreeConstant GetBlendTree(this IStateConstant stateConstant)
{
return stateConstant.BlendTreeConstantArray[0].Data;
}
public static bool GetWriteDefaultValues(this IStateConstant stateConstant)
{
return !stateConstant.Has_WriteDefaultValues() || stateConstant.WriteDefaultValues;
}
public static uint GetId(this IStateConstant stateConstant)
{
if (stateConstant.Has_FullPathID())
{
return stateConstant.FullPathID;
}
else if (stateConstant.Has_PathID())
{
return stateConstant.PathID;
}
else
{
return stateConstant.ID;
}
}
public static Utf8String GetName(this IStateConstant stateConstant, AssetDictionary<uint, Utf8String> tos)
{
if (stateConstant.Has_NameID())
{
return tos[stateConstant.NameID];
}
Utf8String _statePath = tos[stateConstant.ID];
string statePath = _statePath.String; // ParentStateMachineName.StateName
// periods are used for concatenating State and StateMachine Names to get their paths.
// Unity Editor doesn't allow periods in State and StateMachine Names.
int pathDelimiterPos = statePath.IndexOf('.');
if (pathDelimiterPos != -1 && pathDelimiterPos + 1 < statePath.Length)
{
return new Utf8String(statePath[(pathDelimiterPos + 1)..]);
}
return _statePath;
}
}
}