x


How can I import an external text file at player runtime using Javascript?

How can I import a configuration text file into a stand-alone Unity player at runtime so I can change the configuration without recompiling?

more ▼

asked Jan 27 '10 at 01:21 PM

davedev gravatar image

davedev
594 37 41 49

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Unity is .Net/Mono based, so you have access to a significant portion (but not all) of .Net's runtime to do these things, especially if you are only targeting the stand-alone player.

This would be a really simple way (there are about a bazillion other ways) of loading a configuration file using http://System.IO as suggested:

using http://System.IO;

public class GameConfig
{
    //TODO: create some variables to hold the parsed configuration values

    public void Load(string path)
    {
        string config = System.IO.File.ReadAllText(path);

        //TODO: parse the loaded configuration and set the variables to the values
        // contained in the config file.
    }
}
more ▼

answered Jan 27 '10 at 05:34 PM

Duke gravatar image

Duke
418 1 5 11

(comments are locked)
10|3000 characters needed characters left

Files in Resources do get compiled into the runtime, so you'd want to use functions in System.IO.

more ▼

answered Jan 27 '10 at 04:04 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

(deleted my answer which suggested using resources - I had completely the wrong idea about the question)

Jan 27 '10 at 05:44 PM duck ♦♦
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x56

asked: Jan 27 '10 at 01:21 PM

Seen: 2402 times

Last Updated: Jan 27 '10 at 01:21 PM