Unity各种路径获取

转载 2015年11月21日 09:33:12

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;
  }

文档信息

相关文章推荐

unity文件操作路径

1.Resources文件夹  Resources文件夹是一个只读的文件夹,通过Resources.Load()来读取对象。因为这个文件夹下的所有资源都可以运行时来加载,所以Resources文件夹...
  • linxinfa
  • linxinfa
  • 2016年06月15日 11:07
  • 11390

Unity 获取指定资源目录下的所有文件

获取 所有资源 [@MenuItem("Navy/Assets/Test")] static void Test_Compoent(){ //OK //这个不好用~ //Debug.L...

Unity获取场景gameobject的路径

Unity场景里gameobject路径的拷贝,资源,文件夹路径的拷贝。

Unity获取物体在项目工程的目录

//获取被选择物体在项目中的路径目录 using UnityEngine; using System; using UnityEditor; // 该脚本放在 Editor 文件夹下 //选中一个...

Unity3d获取在Asset中选中的目录、资源 的路径

[MenuItem("Tools/testselect")] public static void testselect() { UnityEngine.Object[...

Unity3D各平台Application.xxxPath的路径

iOS/Android/Windows平台应用存储路径,Unity3D在各平台的路径,Application.dataPath/Application.streamingAssetsPath/Appl...
  • ynnmnm
  • ynnmnm
  • 2016年08月19日 19:25
  • 17152

Unity中路径获取拼接

// 替换目录分隔符 输出 / print( Path.AltDirectorySeparatorChar); // 合并 输出 /First/Path\So...

Unity里常用的一些路径等信息

0.  Asset folder的路径:Application.dataPath; 得到的是自磁盘根目录开始的路径。 0. C#自带的: string[] paths = Directory...

Unity资源路径及加载外部资源介绍

Unity3D中的资源路径 路径属性 路径说明 Application.dataPath 此属性用于返回程序的数据文件所在文件夹的路径。例如在Edi...

【转】C#获取当前程序运行路径的方法集合

转载,原文地址:http://www.cnblogs.com/cocoulong/archive/2010/01/30/1660119.html   //获取当前进程的完整路径,包含文件名(进程名...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Unity各种路径获取
举报原因:
原因补充:

(最多只允许输入30个字)