I have an issue.
I need to be able to load all the *.png files at run time from a folder under steamingassets, these are dynamic images and can changed after build.
here is a sample of my code.
using UnityEngine;
using System.IO;
using System.Collections;
public class loadallimages : MonoBehaviour {
// Use this for initialization
void Start () {
GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
string folderpath = Application.streamingAssetsPath + @"/Tiles/";
// string[] FileList = Directory.GetFiles(folderpath, "*.png");//loads only png files
Object[] textures = Resources.LoadAll(folderpath);
int fred = Random.Range(0, textures.Length);
Debug.Log(string.Format("fred is crurrently:{0}", fred));
Debug.Log(textures.Length);
Debug.Log(textures[fred].name);
Texture2D texture = (textures[fred]) as Texture2D;
go.GetComponent<Renderer>().material.mainTexture = texture;
}
}
Resources.LoadAll wont load them at all (fred=0).
Resources.load wont load, I get a list of null objects :(.
code to load each file (note: you have to remove the “.png” from the file name to get the Resource.load to load them)(but it doesn’t)
string[] FileList = Directory.GetFiles(folderpath, "*.png");//loads only png files
Object[] textures = new Object[FileList.Length];
for (int ten =0; ten> FileList.Length;ten++)
{
textures[ten] = Resources.Load(FileList[ten].Substring(0,FileList.Length-4)); // removes the ".png" from the end of the file name
}
I would like the ability to load all the tile images at start up form a streamingassets/tiles folder location to use them then discard them to free up memory.
I understand that placing them in the resources folder and then calling Resources.loadAll(“Tiles”) would load them however the files will be changed after release hence the need to use the steamingassets folder. if there is an option them please help
cheers
D2