How do I load resources (text files, textures, etc.) from within a native plugin? I’m in the process of attempting to implement a mono invoke of Resources.Load(), but I am unsure as to how to handle the Object that will be returned from this operation (assuming it is successful). Any help would be greatly appreciated :).
How do I load resources (text files, textures, etc.) from within a native plugin?
Share
The Unity-supported means for your plugin to load resources directly from the native filesystem is to place those resources into a folder named “StreamingAssets” inside your project. When your Unity-based application is installed, the contents of this folder are copied to the native filesystem (except Android, see below). The path to this folder on the native side varies per platform.
In Unity v4.x and later, this path is available as
Application.streamingAssetsPath;Note that on Android the files you place in StreamingAssets get packaged into a .jar file, though they can be accessed by unzipping the .jar file.
In Unity v3.x, you have to manually construct the path yourself as follows:
Application.dataPath + "/StreamingAssets"Application.dataPath + "/Raw""jar:file://" + Application.dataPath + "!/assets/"Here is a snippet I used to handle this:
Note that on Android, Android 2.2 and earlier cannot directly unpack large .jars (typically larger than 1 MB) so you would need to handle that as an edge case.
References: http://unity3d.com/support/documentation/Manual/StreamingAssets.html, plus http://answers.unity3d.com/questions/126578/how-do-i-get-into-my-streamingassets-folder-from-t.html and http://answers.unity3d.com/questions/176129/accessing-game-files-in-xcode-project.html