I’m in enterprise environnement for develop a solution on Unity 3D. My document are in local area network (on a NAS). And I want to read image in this folder and load it in my solution.
Here a sample of what I want do :
// string file = "file://C:/Medias/m_7.jpg"; => WORK
string file = "file://192.168.1.150/MyDoc/Medias/m_7.jpg"; // => NOT WORK
Texture tex = null;
Uri uri = new Uri(file);
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(uri))
{
yield return uwr.SendWebRequest();
if (string.IsNullOrEmpty(uwr.error))
{
tex = DownloadHandlerTexture.GetContent(uwr);
}
else
{
Debug.Log(uwr.error);
}
}
The adress server is a sample but look like of what I have here.
I can load texture on local drive or on the internet with “UnityWebRequestTexture.GetTexture()” but the method seems not work when the file is on the local network.
I can’t really comment on the LAN aspect specifically, but from what I recall about issues with “file://” I’ve seen around previously, in Windows you actually need to use three /// slashes- two will work in some instances but not others. Can you just quickly verify if that fixes it or not? Hopefully someone with more familiarity with this issue than I will be by soon, if not.
Thank you,
I test with three slashes and also on a mac or Android I want load resources with this way… If someone has an idea my previous code was based on WWW which is obsolete now.
The part about three slashes is not correct. The slashes are required on Windows for local files, for network stuff two is actually correct.
file protocol for non-local files is in general not well defined. Try using computer name instead of IP address. Another thing you can try is smb protocol instead of file, should work for Windows/Samba shares, but be aware that this is not supported across all platforms (should be ok on desktops though).
now you have to make it to the absolute path in a UNIX form, which means prepending another slash (because “//192.168.1.150” is a directory name in this case), so it’s now ///192.168.1.150/MyDoc/…
finally you prepend the file:// shame to it: file://///192.168.1.150/MyDoc/…
Looks very weird, but that’s what it is. Though I think our code supports the relaced form with four slashes just fine (added along with local files with just two slashes due to a very common “mistake”).