rafayali
11/25/2014 - 2:18 PM

Loading textures from an asset path in unity

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;
	}