using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Abstractions.Extractors.Unity.Services;
namespace Abstractions.Extractors.Unity;
/// Extracts an AnimationClip's float curves (attribute/path/keyframes) to JSON. Keyframe
/// tangents are read from AnimationCurve.Keyframe's real field names, inSlope/outSlope.
public sealed class AnimationExtractor : IAssetExtractor
{
public IReadOnlyCollection HandledTypes { get; } = ["AnimationClip"];
public async Task ExtractAsync(ExtractionContext context, CancellationToken cancellationToken = default)
{
try
{
var baseField = context.BaseField;
var animData = new Dictionary
{
["name"] = baseField.Get("m_Name") is { IsDummy: false } n ? n.AsString : "Unknown",
["length"] = baseField.Get("m_Length") is { IsDummy: false } len ? len.AsFloat : 0f,
["frame_rate"] = baseField.Get("m_SampleRate") is { IsDummy: false } rate ? rate.AsFloat : 30f,
["wrap_mode"] = baseField.Get("m_WrapMode") is { IsDummy: false } wrap ? wrap.AsInt : 0,
["curves"] = new List