Search Unity

Read Custom File Type

Discussion in 'Scripting' started by ketchup_scaredcrow, May 24, 2015.

  1. ketchup_scaredcrow

    ketchup_scaredcrow

    Joined:
    Mar 26, 2014
    Posts:
    43
    I'm making a program and this program will rely on outside files for it's operation. Imagine something like Photoshop. With photoshop you can save out as a .psd and you can open .psd's and you can only open them in Photoshop. My question is not how to make or register a file extension but how do I read my custom file type? How does my main program, like photoshop, read the information inside my file with a custom file extension, like .psd's?

    I will be needing to get information such as strings, images and audio from the files for use by the main program.
     
    Last edited: May 24, 2015
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    With System.IO you can read the contents of any file. As long as you have the means to decode it you are away laughing.
     
  3. ketchup_scaredcrow

    ketchup_scaredcrow

    Joined:
    Mar 26, 2014
    Posts:
    43
    Including images and audio? How would I get the images and audio embeded into the file into the main program?
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Typically images and audio will be serialised into a series of bytes in the file. If you have the deserialisation method you can read out all of the bytes and convert them back to their original form. It is fairly simple if you made the original file yourself. Trickier for someone else's format, but still doable.
     
  5. ketchup_scaredcrow

    ketchup_scaredcrow

    Joined:
    Mar 26, 2014
    Posts:
    43
    Thanks for the tips. Obviously it is .net so can you point me generally to which methods I might use for serialization and reading?
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Check out the learn section tutorial which talks about saving an persistiant data.