Search Unity

Reading text for language manager

Discussion in 'Scripting' started by Sparking02, Sep 25, 2017.

  1. Sparking02

    Sparking02

    Joined:
    Sep 10, 2015
    Posts:
    25
    Hello, I was looking for a correct (and now functional way) to read data from a file, I use to work with a plugin I do not remember the name, but it was something like ExcelReaderFactory or something like that, My idea was to create a little "database" on a xls/xlsx file, read it, ask for an ID and depending on the Language selected it would return it, at the moment it works perfectly but only in the editor, after building it, at the moment I use the data I read from the file it marks a Null error, so I was looking if there is a better way (and that actually work on a build project) to read the data ( I pick Excel because is easy for the artist and other people working on the game to modify a sentence)
     
  2. fire7side

    fire7side

    Joined:
    Oct 15, 2012
    Posts:
    1,819
    You could look into json. There are editors around for it, even on line.
     
    Sparking02 likes this.
  3. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I generally use CSV for this. For a parser I just googled "C# CSV parser" and grabbed the most promising link off the first page of search results. Works a treat.
     
    Sparking02 likes this.
  4. Sparking02

    Sparking02

    Joined:
    Sep 10, 2015
    Posts:
    25
    everyone say the same, ok I would try it
     
  5. Sparking02

    Sparking02

    Joined:
    Sep 10, 2015
    Posts:
    25
    But it is also easy for the non-code related people, easy to use? (some people are just scared of even plain text)
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Yes, that's why we use CSV. You can open and edit it in Excel or pretty much any other spreadsheet app (or, in an CSV editor, of which there are many).
     
  7. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    The resx file format is another option. It's supported by .Net, and there are many visual editors out there (here's one, here's another)

    Pick your poison. :D
     
    Sparking02 likes this.
  8. Sparking02

    Sparking02

    Joined:
    Sep 10, 2015
    Posts:
    25
    And it would work if I want to deploy the game on Xbox and Mac?
     
  9. Sparking02

    Sparking02

    Joined:
    Sep 10, 2015
    Posts:
    25
    The same question, it would work on Xbox and Mac? It is now my biggest doubt
     
  10. BlackPete

    BlackPete

    Joined:
    Nov 16, 2016
    Posts:
    970
    I'm not sure why it'd matter. Csv and resx are text files, and it'd be a huge failing in the parser if it wasn't platform agnostic. In fact, resx is basically a glorified XML file. The resx format has also been supported since .Net 1.1.

    That said, I haven't personally tried building for the Mac or Xbox myself.
     
  11. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Same for CSV — it's just a text file. It'll work on any platform.
     
  12. Sparking02

    Sparking02

    Joined:
    Sep 10, 2015
    Posts:
    25
    Well, at the end, I use the Json, there is more documentation that with the CSV and the .resx (also all I found about .resx where closed topics and no working sites)
     
    JoeStrout likes this.