Version: 2023.2
public static string dataPath ;

描述

包含目标设备上的游戏数据文件夹路径(只读)。

该值取决于运行时所基于的平台:

**Unity Editor:**<path to project folder>/Assets

**Mac 播放器:**<path to player app bundle>/Contents

**iOS 播放器:**<path to player app bundle>/<AppName.app>/Data(这是一个只读文件夹,使用 Application.persistentDataPath 来保存数据)。

**Win/Linux 播放器:**<path to executablename_Data folder>(请注意,大多数 Linux 安装都区分大小写!)

**WebGL:**播放器数据文件文件夹的绝对 URL(没有实际的数据文件名)

Android: Normally it points directly to the APK. If you are running a split binary build, it points to the OBB instead.

UWP Apps: The absolute path to the player data folder (this folder is read only, use Application.persistentDataPath to save data)

请注意,PC 上返回的字符串将使用正斜杠作为文件夹分隔符。

对于任何未列出的平台,请在目标平台上运行示例脚本以在调试日志中找到 dataPath 位置。

//Attach this script to a GameObject
//This script outputs the Application’s path to the Console
//Run this on the target device to find the application data path for the platform
using UnityEngine;

public class Example : MonoBehaviour { string m_Path;

void Start() { //Get the path of the Game data folder m_Path = Application.dataPath;

//Output the Game data path to the console Debug.Log("dataPath : " + m_Path); } }