How to get child sprites from a 'Multiple Sprite' Texture?

So, I have a texture with TextureType: Sprite and SpriteMode: Multiple in Unity 4.3.
I used a Sprite Editor to cut out some Sprites from my texture.
Now my sprites are showing as children in the Project window.

How can I access these children in the code?

Lets say Im writing my class and using

public Texture2D txt;

to set a texture in the inspector (by drag and dropping it).
But later I want to access Sprites inside this texture in the code. How ca I do it?

I was looking for a solution to this that would work in builds and not only in the editor (as opposed to swalex’s answer here)

Finally got it to work, so I figured this could help someone in the future:

public Texture2D texture;

...

Sprite[] sprites = Resources.LoadAll<Sprite>(texture.name);

The multi-sprite texture has to be in a Resources folder in your project so that it can be accessed with Resources.LoadAll.

texture is declared as a public Texture2D so that it can be set in the editor.

using System.Linq;
using UnityEngine;

...

string spriteSheet = AssetDatabase.GetAssetPath( txt );
Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath( spriteSheet )
    .OfType<Sprite>().ToArray();

For anyone searching for this topic, it should be noted that there’s a new way of doing this.

In Unity 2017 SpriteAtlas was added. You can make one from the Create menu. If you add a multi-sprite texture to an atlas, you can access the child sprites by using spriteAtlas.GetSprite(“child_sprite_name”), (you can change the individual sub-sprite names in the sprite editor) or get all of them with GetSprites(spriteArray).

For multi-sprite textures I found this to work:

UnityEngine.Object allSprites = AssetDatabase.LoadAllAssetRepresentationsAtPath(“Assets/Textures/” + SpriteTextureName + TextureExtension);

I just did this, it seems to work… might be downsides like taking more memory but draw calls should be kept low.

static void Loadcardfrontatlasnamed(string nameofcardfrontatlas) {
		Sprite[] sprites = Resources.LoadAll<Sprite>(string.Format("sprites/cardfronts/texture_cardfront_{0}", nameofcardfrontatlas));
		atlasCardfront.Clear();
		foreach (Sprite asprite in sprites) {
			atlasCardfront[asprite.name] = asprite;
		}
	}
	static Dictionary<string, Sprite> atlasCardfront = new Dictionary<string, Sprite>();

Then you can just grab a Sprite by name from the static atlasCardfront.
This static function should be called from the static constructor of this class. This all depends on your project and class setup but you probably want to cache the sprites vs filenames early.