- Home /
Export Settings or custom files to release builds
Hello everyone! I got a little question I am building an asset at the moment and I am struggling with something.
I created a settings page where users can enter details and stuff, but how do I get these to the release build? I can save them in files at editor runtime but then when building, these files are ofc not taken with into the build. So what is the best method of doing so ?
I tought of creating automated code based on the settings that gets executed on the first run but that is suboptimal at best.
Any suggestions?
Thanks!
Answer by toddisarockstar · Mar 12, 2016 at 06:41 PM
if you are building for standalone you should make sure you are using the resourse folder for your file path
import System.IO;
//write
if(!File.Exists(Application.dataPath+"/Resources/settings.txt")){
var swmap : StreamWriter = new StreamWriter
(Application.dataPath+"/Resources/settings.txt");
swmap.WriteLine("here are my settings");
swmap.Flush();swmap.Close();}
//read
var loadsettings:TextAsset;
loadsettings=Resources.Load("settings")as TextAsset;
Hello! Thank you for your reply. I figured this was the way to go but I got confused whether Resources I available after a project has been built or not.
A little question, the scripting reference says
The path is relative to any Resources folder
It says Any resources folder. Does this mean I I have a Resources folder as a subfolder somewhere ?
Thank you, T
yes, anything in your assetts folder should carry out to the build. if you use the resourses folder (which is a folder inside your assetts folder). You get some advantages with using the Resourses.load function.
I believe the resources folder should already be there by default but if not you could simple say something like this:
if(!System.IO.Directory.Exists("file path here")){
System.IO.Directory.CreateDirectory("file path here");}
or just put it there manually in unity before the build. depending on what your doing, the File path is not always relative to resourses folders, because of course you can write to any drive wherever you want outside the game folder.
when playing with files usually if you want to write reletive to your game folder you say Application.datapath first.
when you call resource.load i think there is an exeption. i don't think it needs the whole path.