private static bool CreateAnimation(GameObject gameObject, UnityEngine.Object[] frames)
{
Array.Sort <UnityEngine.Object>(frames, (UnityEngine.Object a, UnityEngine.Object b) => EditorUtility.NaturalCompare(a.name, b.name));
string message = string.Format("Create a new animation for the game object '{0}':", gameObject.name);
string directoryName = Path.GetDirectoryName(AssetDatabase.GetAssetPath(frames[0]));
string text = EditorUtility.SaveFilePanelInProject("Create New Animation", "New Animation", "anim", message, directoryName);
if (string.IsNullOrEmpty(text))
{
return(false);
}
AnimationClip animationClip = AnimationSelection.AllocateAndSetupClip(true);
AssetDatabase.CreateAsset(animationClip, text);
AnimationSelection.AddClipToAnimatorComponent(gameObject, animationClip);
animationClip.frameRate = 12f;
ObjectReferenceKeyframe[] array = new ObjectReferenceKeyframe[frames.Length];
for (int i = 0; i < array.Length; i++)
{
array[i] = default(ObjectReferenceKeyframe);
array[i].value = SpriteUtility.RemapObjectToSprite(frames[i]);
array[i].time = (float)i / animationClip.frameRate;
}
EditorCurveBinding binding = EditorCurveBinding.PPtrCurve(string.Empty, typeof(SpriteRenderer), "m_Sprite");
AnimationUtility.SetObjectReferenceCurve(animationClip, binding, array);
return(true);
}