I was just working on a dead simple AssetPostprocessor script to learn the ropes, and I thought I’d post it here for others new to Editor scripting.
This script is mostly useful if you are working with a 3d artist that gives you separate FBX files for each animation for a character. It will print a debug message to the console stating how many frames each animation has. This is handy if you need to recombine them or keep track of the frame count and don’t have Maya to drop into.
Just place this in Editor\CheckAnimationFrames.cs.
using UnityEngine;
using UnityEditor;
using System.Collections;
public class CheckAnimationFrames : AssetPostprocessor {
void OnPostprocessModel (GameObject g) {
// Only operate on FBX files
if (assetPath.IndexOf(".fbx") == -1) {
return;
}
if (EditorUtility.DisplayDialog("FrameCount", "Show number of frames?", "Yes", "No")) {
ShowFrames(g);
}
}
void ShowFrames(GameObject g) {
Animation anim = (Animation)g.GetComponent(typeof(Animation));
foreach (AnimationState state in anim) {
AnimationClip clip = state.clip;
Debug.Log(g.name + " animation data is " + (clip.length * clip.frameRate) + " frames long");
}
}
}