スクリプトによって取得できるパス
About
Application.xxxPathによっていくつかのパスが得られます。標準的に4種類用意されているようなので検証しました。
Script
//一時領域のパス print(Application.temporaryCachePath); //ストリーミングアセットのパス print(Application.streamingAssetsPath); //Unityが利用するデータが保存されるパス print(Application.dataPath); //実行中に保存されるファイルがあるパス print(Application.persistentDataPath);
補足的なTips
詳細は以降の項目を確認してもらうとして、ここでは簡単なメモを残しておきます。
- dataPathには注意する.
- 実行環境で変化するので注意する.特にEditorでの実行と実行ファイルでの実行とで異なる点に注意する.
- tempraryCachePathについて
- Winで実行すると、環境変数が指定する一時ファイルの保存ディレクトリ"TEMP"を参照していることが分かる.
- persistentDataPathについて
- Winで実行すると、"C:/Users/ユーザ名/AppData/LocalLow/DefaultCompany/プロジェクト名"を参照していることが分かる.
Unityアプリケーション(.exe)のあるディレクトリのパスは例えば次のように取得できます。
path = Application.dataPath; if (Application.platform == RuntimePlatform.OSXPlayer) { path += "/../../"; } else if (Application.platform == RuntimePlatform.WindowsEditor) { path += "/../"; } else if (Application.platform == RuntimePlatform.WindowsPlayer) { path += "/../"; }
Manualの翻訳
Application.temporaryCachePath
- Reference原文
- The value is a directory path where temporary data can be stored.
- 簡易翻訳
- 一時データが保存されるディレクトリのパス.
Application.streamingAssetsPath
- Reference原文
- Contains the path to the StreamingAssets folder (Read Only).
- If you have a "StreamingAssets" folder in the Assets folder of your project, it will be copied to your player builds and be present in the path given by Application.streamingAssetsPath.
- Note that on some platforms it is not possible to directly access the StreamingAssets folder because there is no file system access in the web platforms, and because it is compressed into the .apk file on Android.
- On those platforms, a url will be returned, which can be used using the WWW class.
- 簡易翻訳
- StreamingAssetフォルダへのパス.
- プロジェクトのAssetsフォルダ内にStreamingAssetsフォルダがある場合には、プレイヤー向けのビルドの際にコピーされ、Application.streamingAssetsPathで指定されたパスに存在することになる.
- Webプラットフォームにはファイルシステムへのアクセスがないため、そしてAndroidではapkファイルに圧縮されるため、いくつかの(WebとAndroid)プラットフォームではStreamingAssetsに直接アクセスすることができない点に注意する.
- そのようなプラットフォームではWWWクラスで利用することができるURLが返される.
Application.dataPath
- Reference原文
- Contains the path to the game data folder (Read Only).
- The value depends on which platform you are running on:
- 簡易翻訳
- ゲームデータのフォルダのパス.
- 起動時のプラットフォームに依存する.
Application.persistentDataPath
- Reference原文
- The value is a directory path where data expected to be kept between runs can be stored.
- 簡易翻訳
- 実行中にデータが保存されると期待されるディレクトリのパス.
- Unity Editor: <path tp project folder>/Assets
- Mac player: <path to player app bundle>/Contents
- iPhone player: <path to player app bundle>/<AppName.app>/Data
- Win player: <path to executablename_Data folder>
- Web player: The absolute url to the player data file folder (without the actual data file name)
- Flash: The absolute url to the player data file folder (without the actual data file name)
- Note that the string returned on a PC will use a forward slash as a folder separator.
- フォルダの区切りはスラッシュ"/"で返される.