Hello,
I was able to load images from a local directory on my computer, into an array of Texture2Ds without using WWW (which will not work properly when trying to load files from a local drive, even when using ‘File:///c:/…’), or Resources.Load (which will not allow a published game’s ‘experience’ to change based on files that are placed in or taken away from a subfolder that sits right outside the published .exe file’s directory). Here is the code that works with loading images that sit in a sub folder that sits outside the published game’s directory, and I see that the data from the published game changes based on what images sit in the folder…
if (System.IO.Directory.Exists(settings.data_directory_s+"textures/"))
{
Rect rect = new Rect();
DirectoryInfo dir = new DirectoryInfo(settings.data_directory_s+"textures/");
FileInfo[] info = dir.GetFiles("*.*");
int cnt = 0;
foreach (FileInfo f in info)
{
Texture2D tex = null;
byte[] fileData;
if (File.Exists(f.FullName))
{
if (f.FullName.IndexOf(".jpg") == f.FullName.Length - 4 || f.FullName.IndexOf(".bmp") == f.FullName.Length - 4 || f.FullName.IndexOf(".gif") == f.FullName.Length - 4)
{
fileData = File.ReadAllBytes(f.FullName);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData);
textureList.Add(tex);
}
}
cnt++;
}
}
As you can see, I did the image-loading by loading everything bitwise, but I am wondering how to convert an array of bytes into an array of floats that would then go into an audio clip (through AudioClip.SetData()).
What I am looking for is something like …
if (System.IO.Directory.Exists(settings.data_directory_s+"sounds/"))
{
Rect rect = new Rect();
DirectoryInfo dir = new DirectoryInfo(settings.data_directory_s+"sounds/");
FileInfo[] info = dir.GetFiles("*.*");
int cnt = 0;
foreach (FileInfo f in info)
{
AudioClip aud = null;
byte[] fileData;
if (File.Exists(f.FullName))
{
if (f.FullName.IndexOf(".wav") == f.FullName.Length - 4 || f.FullName.IndexOf(".mp3") == f.FullName.Length - 4 || f.FullName.IndexOf(".raw") == f.FullName.Length - 4)
{
fileData = File.ReadAllBytes(f.FullName);
aud = new AudioClip();
aud.LoadSound(fileData);
soundList.Add(aud);
}
}
cnt++;
}
… but there is no ‘AudioClip.LoadSound’, YET. Maybe that is a good idea for a new feature that would automatically convert the raw bytes read from a .wav file, into floats that would go into the data of an AudioClip through the proper format and algorithm that would leave the sound unaltered.