Hey Steph,
There are two ways…
-
If it is a code file like .a, .m. .mm. .c, .cpp it will copy over from Assets/Plugins/iOS to the project…:
Automated plugin integration
Unity iOS supports limited automated
plugin integration.
All the .a,.m,.mm,.c,.cpp located in
Assets/Plugins/iOS will be
automatically merged into produced
Xcode project. Merging is done by
symlinking files from
Assets/Plugins/iOS to the final
destination and this might affect some
workflows. .h files are not included
into Xcode project tree, but they
appear on final destination file
system, thus allowing compilation of
.m/.mm/.c/.cpp. Note: subfolders are
not supported.
-
Since your’s is a text or a json/xml file then you need to make a folder called ‘StreamingAssets’ that will auto copy over to the project. This will copy to a folder called ‘Data/Raw’ in your iOS project folder (although it will not be visible in xcode project but will be in Finder). When you load from ‘StreamingAssets’ you need to use a pathing system like:
Use these methods to get the file in game…
using System;
using System.IO;
using UnityEngine;
public class Pathing
{
public static string AppDataPath
{
get {
return Application.dataPath; // gets app install path...
}
}
// gets streaming assets raw path...
public static Uri AppContentDataUri
{
get {
if(Application.platform == RuntimePlatform.IPhonePlayer) {
var uriBuilder = new UriBuilder();
uriBuilder.Scheme = "file";
uriBuilder.Path = Path.Combine(AppDataPath, "Raw");
return uriBuilder.Uri;
}
else if(Application.platform == RuntimePlatform.Android) {
return new Uri("jar:file://" + Application.dataPath + "!/assets");
}
else {
var uriBuilder = new UriBuilder();
uriBuilder.Scheme = "file";
uriBuilder.Path = Path.Combine(AppDataPath, "StreamingAssets");
return uriBuilder.Uri;
}
}
}
}
If you added your file to the ‘StreamingAssets’ folder in Unity (won’t show in the xcode project but will be there in file system). You can access it by using the above method/property:
string mySettingsFile = Paths.AppContentDataUri + "/myfile.json.txt";
Keep in mind you will still have to change in unity, export initially, but here you can iterate at least to get it right in xcode. Then be sure to update in Unity else it will re-copy over.
Note: You can also just add it to ‘Resources/Data’ on xcode project and expect it to be there on device and access it with the path above. It may take some debugging/logging to be sure you have correct path but that will also work so you can just change in xcode or finder.
Add these methods to get documents folder if putting there.
public static string GetAppSandboxPathIPhone() {
// We need to strip "/myappname.app/Data"
return Path.GetDirectoryName(Path.GetDirectoryName(Application.dataPath));
}
public static string GetAppPersistencePathIPhone() {
return Path.Combine(GetAppSandboxPathIPhone(), "Documents");
}