Unity中的各种路径

来源:互联网 发布:淘宝联盟提现手续费 编辑:程序博客网 时间:2024/06/14 15:01

Application.persistentDataPath

http://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html

Contains the path to a persistent data directory (Read Only).

设备中的公开目录,根据平台的不同而不同。这里面的文件不会因为App升级而删除;

Application.streamingAssetsPath

http://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html

工程目录下面的Assets/StreamingAssets。

Application.temporaryCachePath

http://docs.unity3d.com/ScriptReference/Application-temporaryCachePath.html

Contains the path to a temporary data / cache directory (Read Only).

设备的临时存储路径。

Application.dataPath

http://docs.unity3d.com/ScriptReference/Application-dataPath.html

游戏数据的存储路径:

Contains the path to the game data folder (Read Only).

The value depends on which platform you are running on:

Unity Editor: <path to 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.

参考代码:

[cpp] view plain copy
  1. public static string GetStreamingFilePath( string filename)  
  2.   {  
  3.     string path = "";  
  4.   
  5.   
  6.     if ( Application.platform == RuntimePlatform .OSXEditor || Application.platform == RuntimePlatform .OSXPlayer ||  
  7.       Application.platform == RuntimePlatform .WindowsEditor || Application.platform == RuntimePlatform .WindowsPlayer)  
  8.       path = Application.dataPath + "/StreamingAssets/" + filename;  
  9.     else if ( Application.platform == RuntimePlatform .IPhonePlayer)  
  10.       path = Application.dataPath + "/Raw/" + filename;  
  11.     else if ( Application.platform == RuntimePlatform .Android)  
  12.       path = "jar:file://" + Application .dataPath + "!/assets/" + filename;  
  13.     else  
  14.       path = Application.dataPath + "/config/" + filename;  
  15.   
  16.   
  17.     return path;  
  18.   }  
  19.   
  20.   
  21.   
  22.   public static string GetPersistentFilePath( string filename)  
  23.   {  
  24.     string filepath;  
  25.   
  26.   
  27.     if ( Application.platform == RuntimePlatform .OSXEditor || Application.platform == RuntimePlatform .OSXPlayer ||  
  28.       Application.platform == RuntimePlatform .WindowsEditor || Application.platform == RuntimePlatform .WindowsPlayer)  
  29.       filepath = Application.dataPath + "/StreamingAssets/" + filename;  
  30.     else if ( Application.platform == RuntimePlatform .IPhonePlayer || Application.platform == RuntimePlatform .Android)  
  31.       filepath = Application.persistentDataPath + "/" + filename;  
  32.     else  
  33.     {  
  34.       filepath = Application.persistentDataPath + "/" + filename;  
  35.     }  
  36. #if UNITY_IPHONE  
  37.     iPhone.SetNoBackupFlag(filepath);  
  38. #endif  
  39.     return filepath;  
  40.   }  
0 0