I have around 3000 animations stored in an fbx together with an avatar and a shape.
I would like to have only the animation extracted.
To do that, I select the fbx, then click the animation and duplicate it.
This works for.
However, it takes ages.
I would now like to do this via an editor script, but I have never written one before.
Would anybody with editor scripting experience perhaps lend me a helping hand and tell me how it should be done?
This would be really, really nice.
I can give you a few pointers, though there’ll still be a fair amount of trial and error with what I give you, and it’ll be up to you to hook all this together.
To start off, you’ll want to use MenuItem as your kick-off function. From there, you should be able to use Selection.objects to get everything that’s selected.
From here, you’ll be using AssetDatabase heavily. Loop through the selected objects, and use GetAssetPath on each one.
You should at that point be able to use .LoadAllAssetsAtPath, which I believe will get you all four things you see there when you unfold it, and you can distinguish between them based on their .GetType() result - the prefab (GameObject), the mesh (Mesh), air_squat (AnimationClip), and the avatar (not sure what type that’d be offhand).
If you’ve got an AnimationClip, you should be able to instantiate that, and then use .CreateAsset at the location you’d like it to end up.