I was wondering if it would be possible to read all images in for example C:\images\ in an array, and then load them one by one by using path name (sort of like a simple picture viewer). I imagine the process would be something like;
- Read path to all files in folder and store those that ends with jpg or png in array.
- Load image function with applied path.
- Wait X seconds.
- Load next image.
etc.
This only needs to run on Windows.
This should be a good start for you needs.
using UnityEngine;
using System.Collections;
using System.IO;
public class LoadImage : MonoBehaviour {
// Use this for initialization
void Start () {
StartCoroutine("load_image");
}
// Update is called once per frame
void Update () {
}
IEnumerator load_image()
{
string[] filePaths = Directory.GetFiles(@"C:\TEMP\", "*.png"); // get every file in chosen directory with the extension.png
WWW www = new WWW("file://" + filePaths[0]); // "download" the first file from disk
yield return www; // Wait unill its loaded
Texture2D new_texture = new Texture2D(512,512); // create a new Texture2D (you could use a gloabaly defined array of Texture2D )
www.LoadImageIntoTexture(new_texture); // put the downloaded image file into the new Texture2D
this.renderer.material.mainTexture = new_texture; // put the new image into the current material as defuse material for testing.
}
}
1 Like
Thank you very much Malzbier 