Search code examples
unity-game-enginewindows-phonesaveinternal-storage

How can I create and save files to a directory in internal storage on windows phone with unity3d


How can I save a file (doc or image) directly to a specified directory (will be created first time and second will check if exist put data or create and append ) in internal storage on windows phone with unity without use fileOpenPicker? This thinks I need for windows phone 10 from unity3D. Any ideea, advice is appreciated !


Solution

  • Typically you'd save data in the Application.persistentDataPath. Most of System.IO.File is available for UWP apps so you can use that directly. If you're targeting Windows Phone 8.1 then use the alternate UnityEngine.Windows.File

    If you want let the user specify a directory or use a library then you'll need to branch out from what Unity provides and use the underlying WinRT StorageFile API. See Quickstart: Reading and writing files.

    To call WinRT classes in Unity wrap them in #if NETFX_CORE or #if WINDOWS_UWP blocks so isn't called in contexts (such as the Unity Editor) that don't have access to the Windows Runtime.

    See the Unity3d Windows Store Apps docs for more info.