Location of Application.persistentDataPath in a build
In the answer below:
- companyname = Company name from the Build Settings
- productname = Product name from the Build Settings
Windows:
C:\Users\<userprofile>\AppData\LocalLow\<companyname>\<productname>
Windows Store:
%userprofile%\AppData\Local\Packages\<productname>\LocalState
Mac:
~/Library/Application Support/companyname/productname
older version of Unity on Mac:
~/Library/Caches folder
~/Library/Application Support/unity.companyname.productname.
Linux:
$XDG_CONFIG_HOME/unity3d/<companyname>/<productname>
which is the-same as
~/.config/unity3d/<companyname>/<productname>
Android:
/Data/Data/com.<companyname>.<productname>/files
with SD card on the Android device:
/storage/sdcard0/Android/data/com.<companyname>.<productname>/files
iOS:
/var/mobile/Containers/Data/Application/<RandomFolderName>/Documents
Example of the RandomFolderName full name:
/var/mobile/Containers/Data/Application/<055811B9-D125-41B1-A078-F898B06F8C58>/Documents
On iOS, you will be given access to the app's sandbox which is the Document folder. You must create folder inside this directory in order to create a new file inside it.
If you have a default data values in a json file, put the file in Assets/Resources folder so that it will be read-only then read it with TextAsset
. When the game loads, you can use PlayerPrefs
to check if this is the first time the game being loaded.
If this is the first time, use the value from TextAsset.text
. If it is not use then value saved with the DataHandler
class.
Roughly something like this:
if (PlayerPrefs.GetInt("FIRSTTIMEOPENING", 1) == 1){ Debug.Log("First Time Opening"); //Set first time opening to false PlayerPrefs.SetInt("FIRSTTIMEOPENING", 0); //USE TextAsset to load data TextAsset txtAsset = (TextAsset)Resources.Load("player", typeof(TextAsset)); string tileFile = txtAsset.text; PlayerInfo pInfo = JsonUtility.FromJson<PlayerInfo>(tileFile);}else{ Debug.Log("NOT First Time Opening"); //USE DataHandler to load data PlayerInfo pInfo = DataHandler.loadData<PlayerInfo>("player");}