Create a Sprite Animation Clip in Code

I am trying to construct an Animation clip in C#

AnimationClip animClip = new AnimationClip();			
Keyframe[] ks;
ks = new Keyframe[4];
ks[0] = new Keyframe(0f, 0f);
ks[1] = new Keyframe(1f, 1f); 
ks[2] = new Keyframe(2f, 2f); 
ks[3] = new Keyframe(3f, 3f); 
AnimationCurve _curve = new  AnimationCurve(ks);			
animClip.SetCurve("TestAnimation2", typeof(SpriteRenderer), "Sprite", _curve);
animClip.wrapMode = WrapMode.Loop;
game_object.AddComponent ("Animation");
game_object.animation.AddClip (animClip, "AnimationCurve7");
game_object.animation.Play("AnimationCurve7");

The above works? however :

How do I add a different sprite to each keyframe?

take a look at object reference keys

		ArrayList curves = (ArrayList)paths[path];
		
		for (int i = 0; i < curves.Count; i++) {
			EditorCurveBinding binding = (EditorCurveBinding)curves*;*
  •   		AnimationCurve curve = AnimationUtility.GetEditorCurve(animationClip, binding);*
    
  •   		ObjectReferenceKeyframe[] objectReferenceCurve = null;*
    
  •   		if (curve != null) {*
    
  •   			AnimationUtility.SetEditorCurve(animationClip, binding, null);*
    
  •   		} else {*
    
  •   			objectReferenceCurve = AnimationUtility.GetObjectReferenceCurve(animationClip, binding);*
    
  •   			AnimationUtility.SetObjectReferenceCurve(animationClip, binding, null);*
    
  •   		}*
    
  •   		if (path == oldPath) {*
    
  •   			binding.path = newPath;*
    
  •   		}*
    
  •   		if (curve != null) {*
    
  •   			AnimationUtility.SetEditorCurve(animationClip, binding, curve);*
    
  •   		} else {*
    
  •   			AnimationUtility.SetObjectReferenceCurve(animationClip, binding, objectReferenceCurve);*
    
  •   		}*
    
  •   	}*
    

Ey man, I do that. I think this is good, this is my code:

using UnityEngine;
using System.Collections;
using System;
using System.Reflection;

public class CharAnimation : MonoBehaviour {
	/*
		Character sprites positions:

		0 => Walking down 1
		1 => Standing down
		2 => Walking down 2
		3 => Walking left 1
		4 => Standing left
		5 => Walking left 2
		6 => Walking right 1
		7 => Standing right
		8 => Walking right 2
		9 => Walking up 1
		10 => Standing up
		11 => Walking up 2

	 */

	private string currentAnimation = "StandDown";
	private int frame = 0;
	private int animationFrames = 20; // PAR NUMBER

	private Sprite[] sprites = new Sprite[12];
	private SpriteRenderer rend;

	Animator animator = new Animator();

	public void Awake(){
		rend = (SpriteRenderer) this.GetComponent<SpriteRenderer>();
	}

	public void Start () {

	}

	public void Update(){
		if(frame == animationFrames) frame = 0;
		frame++;

		callAnimation();
	}

	private void callAnimation(){
		if(currentAnimation 	 == "WalkUp") 	  WalkUp();
		else if(currentAnimation == "WalkDown")   WalkDown();
		else if(currentAnimation == "WalkLeft")   WalkLeft();
		else if(currentAnimation == "WalkRight")  WalkRight();

		else if(currentAnimation == "StandUp") 	  StandUp();
		else if(currentAnimation == "StandDown")  StandDown();
		else if(currentAnimation == "StandLeft")  StandLeft();
		else if(currentAnimation == "StandRight") StandRight();
	}

	private void changeOnFrame(int f1, int f2){
		if(frame == 1) rend.sprite = sprites[f1];
		else if(frame == animationFrames/2) rend.sprite = sprites[f2];
		else if(frame == animationFrames) 	rend.sprite = sprites[f1];
	}

	private void WalkUp(){
		changeOnFrame(9,11);
	}

	private void WalkDown(){
		changeOnFrame(0,2);
	}

	private void WalkLeft(){
		changeOnFrame(3,5);
	}
	
	private void WalkRight(){
		changeOnFrame(6,8);
	}

	private void StandUp(){
		if(frame == 1) rend.sprite = sprites[10];
	}

	private void StandDown(){
		if(frame == 1) rend.sprite = sprites[1];
	}

	private void StandLeft(){
		if(frame == 1) rend.sprite = sprites[4];
	}

	private void StandRight(){
		if(frame == 1) rend.sprite = sprites[7];
	}

	public void setSprites(Sprite[] sprites){
		this.sprites = sprites;
	}

	public void changeAnimation(string animation){
		frame = 0;
		currentAnimation = animation;
	}
}

It might help if you look at:

EditorCurveBinding _Curves2 = AnimationUtility.GetObjectReferenceCurveBindings (anim);