Jeremy Pritts 42d62a0a9e More forgiving asset resolution
* Failed type checks return null
* Bad dependency numbers return null
* Remove GetAsset methods
* Make asset processing more lenient about null references
2023-11-13 01:25:36 -05:00

54 lines
1.3 KiB
C#

using AssetRipper.Assets;
using AssetRipper.Assets.Metadata;
using AssetRipper.SourceGenerated.Classes.ClassID_1;
using AssetRipper.SourceGenerated.Classes.ClassID_111;
using AssetRipper.SourceGenerated.Classes.ClassID_74;
using AssetRipper.SourceGenerated.Classes.ClassID_95;
using AssetRipper.SourceGenerated.NativeEnums.Global;
namespace AssetRipper.SourceGenerated.Extensions
{
public static class AnimationClipExtensions
{
public static bool GetLegacy(this IAnimationClip clip)
{
if (clip.Has_Legacy_C74())
{
return clip.Legacy_C74;
}
return clip.AnimationType_C74 == (int)AnimationType.Legacy;
}
public static IEnumerable<IGameObject> FindRoots(this IAnimationClip clip)
{
foreach (IUnityObjectBase asset in clip.Collection.Bundle.FetchAssetsInHierarchy())
{
if (asset is IAnimator animator)
{
if (animator.ContainsAnimationClip(clip))
{
IGameObject? gameObject = animator.GameObjectP;
if (gameObject is not null)
{
yield return gameObject;
}
}
}
else if (asset is IAnimation animation)
{
if (animation.ContainsAnimationClip(clip))
{
IGameObject? gameObject = animation.GameObjectP;
if (gameObject is not null)
{
yield return gameObject;
}
}
}
}
yield break;
}
}
}