Hello I am trying to loop through a folder and get a list of files in that folder, then display them in-game. I can get the files good, but I am having a hard time displaying them. What would be the best way to go about this?
Here is my code.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine.UI;
public class MeshUpload : MonoBehaviour
{
// Text to Display the directory.
static Text directoryText;
// String to store the Mesh Directory Path
public string meshdirPath;
// Input Field for Mesh Directory Input Field
public InputField meshdirInput;
///Variables for displaying the directory contents
private string dirOutputString = "";
//A string that stores the selected file or an error message
private string outputMessage = "";
void Start ()
{
directoryText = GameObject.Find ("MeshUploadDirText").GetComponent<Text> ();
//Append the '@' verbatim to the directory path string
this.meshdirPath = @"" + this.meshdirPath;
string [] fileEntries = Directory.GetFiles(meshdirPath);
foreach(string fileName in fileEntries)
ProcessFile(fileName);
foreach (string fileName in fileEntries)
{
directoryText.text = fileEntries.ToString ();
}
}
void Update ()
{
// Make the Directory string sync with the input field text.
meshdirPath = meshdirInput.text;
}
// Insert logic for processing found files here //
public static void ProcessFile(string path)
{
Debug.LogWarning("Processed file: " + path);
directoryText.text = path;
}
}
Should I instantiate different text objects for each file found? I’m pretty confused at this point.
Thanks for your time!