|
Yes, I realize that I could simply make the extension of my CSV file .TXT and use TextAsset to load it, however I do not want to do this. The CSV extension must remain as-is. Basically I have a CSV file that I need to load and get the full text from. I can't use TextAsset because it's not a TXT file, and I've tried using Resources.Load(), however I'm not sure what type to cast it to. How can I load a CSV file and access its contents? I tried using System.IO.StreamReader, and while this works in the editor, it does not work in the web player.
(comments are locked)
|
|
To quote from: Best way to output data from Unity: "...not available in the webplayer for security reasons." The extension doesn't matter, the Browser simply isn't allowed to read or write to the local machine. You could either make your program a stand-alone executable, or put the datafile on the Server. Update: to demonstrate this is an issue with the web-player, try building a standalone executable. Your System.IO.StreamReader code should read the file with no problem (assuming no bugs). Does that solve your problem? If your answer is "no, I want the Browser to read the file", then sorry, it won't work. Depending on the type of data, you might be able to use PlayerPrefs. Also see Does Unity have cookies? Since you appear to want a .csv file, probably not, but I thought I'd mention them. The question isn't about saving files, it's about loading them.
Jun 04 '10 at 04:39 PM
Tetrad
It doesn't matter if it's about saving or loading, the web player cannot read or write to the disk at all, for security purposes. This isn't possible, and he'd have to make the game a standalone EXE.
Jun 04 '10 at 08:52 PM
qJake
I know a little more background about this question than what's in the question. Basically the question should be "Can you use Resources.Load to load a file as a text asset that doesn't have the .txt extension". It's not about loading a file outside the unity bundle.
Jun 05 '10 at 04:52 PM
Tetrad
But is it about loading a file from the webplayer? Because that's what is in the title :) A standalone executable can read any type of file using .Net http://System.IO. A Browser can not read anything from the user's hard drive, regardless of file type.
Jun 05 '10 at 05:42 PM
Cyclops
This particular use case doesn't involve loading a file off the user's machine. The web player/streamreader stuff is a red herring that was intended to say "hey I tried doing it this way and found out it obviously doesn't work on the web player".
Jun 05 '10 at 05:53 PM
Tetrad
(comments are locked)
|
|
Unity Web player does not allow file manipulation(read or write). The best way to do this is using WWW in Unity to retrieve information from the file via PHP. Since CSV basically contains comma separated valued text, they can be passed echoed out as it is and on the unity side they can be split in an array using ',' (comma) delimiter. Let me know if you need more information or a sample code.
(comments are locked)
|

Let me ask the obvious question, which I should have asked before :) Where is the file located?
And a second question - why do you want to keep the .csv extension? Is there a specific need, say another program reads/writes it? Depending on the reason, there may also be a solution or work-around for that.