Skip to content

Instantly share code, notes, and snippets.

@rafayali
Created November 25, 2014 14:18
Show Gist options
  • Save rafayali/fc717cb0b574d5dfaf1d to your computer and use it in GitHub Desktop.
Save rafayali/fc717cb0b574d5dfaf1d to your computer and use it in GitHub Desktop.
Loading textures from an asset path in unity
string relativePathToAssets = "//GUI//productImages2//";
List<Texture> LoadTextures ()
{
List<Texture> textures = new List<Texture>();
string[] productImagesNames = Directory.GetFiles(Application.dataPath + relativePathToAssets, "*.jpg", SearchOption.AllDirectories);
foreach(string imagePath in productImagesNames){
string relativeImagePath = ("Assets" + imagePath.Replace(Application.dataPath, "")).Replace("//","/");
textures.Add(AssetDatabase.LoadAssetAtPath(relativeImagePath, typeof(Texture)) as Texture);
}
return textures;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment