Search Unity

UWP file access

Discussion in 'Windows' started by Grisu1004, Jan 1, 2016.

  1. Grisu1004

    Grisu1004

    Joined:
    Aug 25, 2015
    Posts:
    7
    I am using Unity 5.3.1, VS 2015 on a Windows 10 machine.
    When I am trying to read the contents of a directory I use the following code:

    Code (CSharp):
    1.     public IEnumerator LoadImages(string Album)
    2.     {
    3.         WWW w;
    4.         Texture2D t2D;
    5.  
    6.         //WORKING
    7.         //string fn = @"D:\Daten\Benutzerprofile\Christian\Pictures\DSC00044.JPG";
    8.         //NOT WORKING, BECAUSE Environment... not available
    9.         foreach (string fn in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\" + Album, "*.jpg"))
    10.         {
    11.             w = new WWW("file://" + fn.Replace("\\", "/"));
    12.             yield return w;
    13.             if (w.error != null)
    14.             {
    15.                 Debug.Log("Error: " + w.error);
    16.                 yield break;
    17.             }
    18.             else
    19.             {
    20.                 t2D = new Texture2D(256, 256, TextureFormat.DXT1, true);
    21.                 w.LoadImageIntoTexture(t2D);
    22.                 Images.Add(t2D);
    23.             }
    24.         }
    25.     }
    The code works fine within the editor (on my windows 10 machine!), but when I build the game I end up with an compile error "Environment contains no definition for GetFolderPath" (same with SpecialFolder) in the built uwp solution.

    If I only access ONE file (see code above //string fn = "D:\Daten\Benutzerprofile\Christian\Pictures\DSC00044.JPG";) it works in the built uwp version too, so the only problem is to get all files of a (well known) directory ...

    What is the recommend way for accessing local files (when building a cross platform game with unity)?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,732