您的位置:首页 > 移动开发 > Unity3D

unity3d深入学习笔记2:项目数据路径

2016-02-17 15:08 399 查看
首先贴上一段项目中的代码:

privatestatic readonly string pathURL =
#ifUNITY_ANROID
"jar:file://" +Application.dataPath + "!/assets/";
#elifUNITY_IPHONE
Application.dataPath +"/Raw/";
#elifUNITY_STANDALONE_WIN || UNITY_EDITOR
"file://" +Application.dataPath + "/StreamingAssets/";
#else
string.Empty;
#endif

就是当设备不同的时候,项目的数据路径也设置不同的值,是一个只读的字符串类型。添加一个get接口就可以轻松得到这个路径

下面是unity圣典的介绍:

Application.dataPath
数据路径

static var dataPath : string

Description描述
Contains the path to the game data folder (Read Only).
包含游戏数据文件夹的路径(只读)。
The value depends on which platform you are running on:
这个值依赖于运行的平台:
Unity Editor: <path tp project folder>/Assets

Unity 编辑器:<工程文件夹的路径>/Assets

Mac player: <path to player app bundle>/Contents

Mac播放器:<到播放器应用的路径>/Contents

iPhone player: <path to player appbundle>/<AppName.app>/Data

iPhone播放器:<到播放器应用的路径>/<AppName.app>/Data

Win player: <path to executablename_Data folder>

Win播放器:<
包含可执行播发器的文件夹的路径>\Data

Dashboard widget: <path to the dashboard widget bundle>

Dasboard窗口:< dashboard widget bundle的路径>

Web player: The absolute url to the player data file folder (without theactual data file name)

网络播放器:到播放器数据文件夹的绝对路径(没有实际的数据文件名称)
Note that the string returned on a PC will use a forwardslash as a folder separator.

值得注意的是如果在PC上使用时需要在每个文件夹前加入斜杠
using UnityEngine;
using System.Collections;

public class example :
MonoBehaviour {
publicvoid Awake() {

print(Application.dataPath);
}
}
// print the pathto the data folder
//
打印到数据文件夹的路径

print (Application.dataPath);

引用来自unity圣典:http://game.ceeger.com/Script/Application/Application.dataPath.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: