Skip to content

Instantly share code, notes, and snippets.

@drawcode
Created January 18, 2013 21:36
Show Gist options
  • Select an option

  • Save drawcode/4568817 to your computer and use it in GitHub Desktop.

Select an option

Save drawcode/4568817 to your computer and use it in GitHub Desktop.
public static string GetActualFilePath( string filename ) {
// Prefer our persistent data path
Debug.Log("Checking for " + Application.persistentDataPath + "/" + filename + ".unity3d");
if (File.Exists(Application.persistentDataPath + "/" + filename + ".unity3d")) {
Debug.Log("File exists in persistent data path!");
return "file://" + Application.persistentDataPath + "/" + filename + ".unity3d";
}
// Check platform-specific data path.
if (Application.platform == RuntimePlatform.IPhonePlayer) {
if (File.Exists(Application.dataPath + "/Raw/" + filename + ".unity3d")) {
return "file://" + Application.dataPath + "/Raw/" + filename + ".unity3d";
}
} else if (Application.platform == RuntimePlatform.Android) {
if (File.Exists(Application.dataPath + "!/assets/" + filename + ".unity3d")) {
return "jar:file://" + Application.dataPath + "!/assets/" + filename + ".unity3d";
}
} else if (Application.platform == RuntimePlatform.OSXWebPlayer || Application.platform == RuntimePlatform.WindowsWebPlayer) {
if (File.Exists(Application.dataPath + "/StreamingAssets/" + filename + ".unity3d")) {
return Application.dataPath + "/StreamingAssets/" + filename + ".unity3d";
}
} else {
if (File.Exists(Application.dataPath + "/StreamingAssets/" + filename + ".unity3d")) {
return "file://" + Application.dataPath + "/StreamingAssets/" + filename + ".unity3d";
}
}
return "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment