Search Unity

Import file via Itunes - Unity App

Discussion in 'Scripting' started by longbottomup, Mar 21, 2015.

  1. longbottomup

    longbottomup

    Joined:
    Nov 2, 2013
    Posts:
    49
    I want to make a app-reader demo by Unity, a Simple Book Reader for only me, but i don't know how import file(audio, image, etc..) via Itunes, like that:

    Someone can tell me the keyword, toolkit or something else, thank you very much.
     
  2. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
  3. longbottomup

    longbottomup

    Joined:
    Nov 2, 2013
    Posts:
    49
  4. longbottomup

    longbottomup

    Joined:
    Nov 2, 2013
    Posts:
    49
    Sorry about that, but i have a question: how to import files into my apps after add files via itunes.
     
  5. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    I think they are all in Documents folder, so you can read them from here:
    Code (csharp):
    1. string path =Application.dataPath.Substring(0,Application.dataPath.Length-5);
    2. path = path.Substring(0, path.LastIndexOf('/'));
    3. path = path + "/Documents/"+yourfile;
     
    longbottomup likes this.
  6. longbottomup

    longbottomup

    Joined:
    Nov 2, 2013
    Posts:
    49
    Thanks pro, you're so thoughtful. By the way, can you explain your code? What is "yourfile"? Ex: i'm add two images: "image1.jpg", "image2.png". How can i show on screen. Sorry for my broken english.
     
  7. proandrius

    proandrius

    Unity Technologies

    Joined:
    Dec 4, 2012
    Posts:
    544
    Code generates a path to documents folder, where all the images from itunes.
    yourfile is the file you want to get. So in your case it would be, for example "image1.jpg".

    Then when you know that path you will have to read all bytes from that file using eg. this: https://msdn.microsoft.com/en-us/library/system.io.file.readallbytes(v=vs.110).aspx

    Then when you have all the bytes you will need to load them into the image using Texture2D.LoadImage(bytes[]);
    http://docs.unity3d.com/ScriptReference/Texture2D.LoadImage.html
     
    longbottomup likes this.
  8. longbottomup

    longbottomup

    Joined:
    Nov 2, 2013
    Posts:
    49
    How can i know the files of users want? can i use: "*.jpg, *.png"?