Skip to content

Instantly share code, notes, and snippets.

@NNNIC
Last active March 9, 2023 07:27
Show Gist options
  • Save NNNIC/93c96065bf1018ef0c86b2708336c270 to your computer and use it in GitHub Desktop.
Save NNNIC/93c96065bf1018ef0c86b2708336c270 to your computer and use it in GitHub Desktop.
Dump AnimationClip Sample
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class DumpAnimationClip {
[MenuItem("Assets/dump animation clip")]
static void Dump()
{
if (Selection.assetGUIDs==null || Selection.assetGUIDs.Length!=1)
{
Debug.LogError("Select an animation clip in the project window");
return;
}
var path = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);
var clip = AssetDatabase.LoadAssetAtPath<AnimationClip>(path);
if (clip==null)
{
Debug.LogError("Select an animation clip in the project window");
return;
}
{
Debug.Log("# AnimationUtility.GetCurveBindings #");
var allbindlings = AnimationUtility.GetCurveBindings(clip);
foreach(var bind in allbindlings)
{
var keyframes = AnimationUtility.GetObjectReferenceCurve(clip,bind);
if (keyframes!=null)
{
Debug.Log( bind.path + "/" + bind.propertyName +", keys" + keyframes.Length );
}
else
{
var curves = AnimationUtility.GetEditorCurve(clip,bind);
string s = null;
for(var i = 0; i<curves.length; i++)
{
if (s!=null) s+="-";
s+= "(" + curves[i].time + ":" + curves[i].value +")";
}
Debug.Log( bind.path + "/" + bind.propertyName + "(" + bind.type + "), curve keys = " + curves.keys.Length +"," + s);
}
}
}
{
Debug.Log("# AnimationUtility.GetCurveBindings #");
var allbindlings = AnimationUtility.GetObjectReferenceCurveBindings(clip);
foreach(var bind in allbindlings)
{
var keyframes = AnimationUtility.GetObjectReferenceCurve(clip,bind);
if (keyframes!=null)
{
Debug.Log( bind.path + "/" + bind.propertyName +", keys" + keyframes.Length );
}
else
{
var curves = AnimationUtility.GetEditorCurve(clip,bind);
string s = null;
for(var i = 0; i<curves.length; i++)
{
if (s!=null) s+="-";
s+= "(" + curves[i].time + ":" + curves[i].value +")";
}
Debug.Log( bind.path + "/" + bind.propertyName + "(" + bind.type + "), curve keys = " + curves.keys.Length +"," + s);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment