Unity各种路径

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.

参考代码:

public static string GetStreamingFilePath( string filename)
  {
    string path = "";


    if ( Application.platform == RuntimePlatform .OSXEditor || Application.platform == RuntimePlatform .OSXPlayer ||
      Application.platform == RuntimePlatform .WindowsEditor || Application.platform == RuntimePlatform .WindowsPlayer)
      path = Application.dataPath + "/StreamingAssets/" + filename;
    else if ( Application.platform == RuntimePlatform .IPhonePlayer)
      path = Application.dataPath + "/Raw/" + filename;
    else if ( Application.platform == RuntimePlatform .Android)
      path = "jar:file://" + Application .dataPath + "!/assets/" + filename;
    else
      path = Application.dataPath + "/config/" + filename;


    return path;
  }



  public static string GetPersistentFilePath( string filename)
  {
    string filepath;


    if ( Application.platform == RuntimePlatform .OSXEditor || Application.platform == RuntimePlatform .OSXPlayer ||
      Application.platform == RuntimePlatform .WindowsEditor || Application.platform == RuntimePlatform .WindowsPlayer)
      filepath = Application.dataPath + "/StreamingAssets/" + filename;
    else if ( Application.platform == RuntimePlatform .IPhonePlayer || Application.platform == RuntimePlatform .Android)
      filepath = Application.persistentDataPath + "/" + filename;
    else
    {
      filepath = Application.persistentDataPath + "/" + filename;
    }
#if UNITY_IPHONE
    iPhone.SetNoBackupFlag(filepath);
#endif
    return filepath;
  }

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值