文山网站建设代理,中公教育培训机构官网,广安发展建设集团公司网站,旅游订票网站开发目录
1 unity是一个跨平台的引擎
1.1 使用 Application类#xff0c;去读写文件
1.2 路径特点
1.2.1 相对位置/相对路径#xff1a;
1.2.2 固定位置/绝对路径#xff1a;
1.3 测试方法#xff0c;仍然挂一个C#脚本在gb上
2 游戏数据文件夹路径#xff08;只读…目录
1 unity是一个跨平台的引擎
1.1 使用 Application类去读写文件
1.2 路径特点
1.2.1 相对位置/相对路径
1.2.2 固定位置/绝对路径
1.3 测试方法仍然挂一个C#脚本在gb上
2 游戏数据文件夹路径只读Application.dataPath
2.1 Application.dataPath
2.2 跨平台时不同相对路径需要拼接外部路径
2.3 特点
2.4 测试
3 Application.streamingAssetsPath 只读
3.1 Application.streamingAssetsPath
3.2 在unity的编辑器默认是没有的也不显示
3.3 特点
3.4 测试
4 游戏持久化文件路径 persistentDataPath 可读可写 4.1 persistentDataPath
4.2 特点
4.3 测试
5 游戏的临时文件夹 Application.temporaryCachePath
5.1 Application.temporaryCachePath
5.2 测试 1 unity是一个跨平台的引擎
unity输出的游戏包可以适应各种平台比如 android , ios , 和一些主机游戏平台 1.1 使用 Application类去读写文件
比如 Application.datapath比如 Application.persistenpath知道文件在哪儿才可以去读才可以去存 1.2 路径特点 1.2.1 相对位置/相对路径
dataPath和streamingAssetsPath这两个属性的返回值一般是相对于程序安装目录的位置由于是相对位置适用于在多平台移植中设置要读取外部数据文件的路径并且者2个文件夹时只读的 1.2.2 固定位置/绝对路径
persistentDataPath和temporaryCachePath这两个属性的返回值一般是程序所在平台的固定位置对于不同的平台其位置是不一样的适合存放程序运行过程中产生的一些数据文件可读可写 1.3 测试方法仍然挂一个C#脚本在gb上 2 游戏数据文件夹路径只读Application.dataPath
2.1 Application.dataPath
Application.dataPath此属性用于返回程序的数据文件所在文件夹的路径(只读)。返回路径为相对路径不同的游戏平台的数据文件保存路径不同。windows的unity编辑器下这个文件夹路径其实就是 unity 编辑器的工程Assets目录路径 2.2 跨平台时不同相对路径需要拼接外部路径
unity可以跨平台Application.dataPath在不同的平台下的路径是不同的
windows的unity编辑器下是 unity 编辑器的工程Assets目录路径Win player包含可执行文件的文件夹路径/DataMac player:应用程序路径/AppName.app/Data 2.3 特点
只读加密压缩 2.4 测试
Application.dataPath //返回的就是unity现在项目的Assets目录Application.dataPath/Readme //返回的是拼接的路径下的文件Application.dataPathApplication.dataPath/Readme using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ApplicationTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){Debug.Log(Application.dataPathApplication.dataPath);Debug.Log(Application.dataPathApplication.dataPath/Readme);}// Update is called once per framevoid Update(){}
}3 Application.streamingAssetsPath 只读
3.1 Application.streamingAssetsPath
streamingAssetsPath此属性用于返回流数据的缓存目录返回路径为相对路径适合设置一下外部数据文件的路径windows的unity下这个文件夹路径其实就是 unity 编辑器的工程Assets目录路径下一个子文件夹 3.2 在unity的编辑器默认是没有的也不显示
但是在unity的编辑器默认是没有的也不显示需要手动创建需要在工程里 手动创建这个文件夹,Application.streamingAssetsPath 3.3 特点
只读加密压缩
Application.streamingAssetsPath游戏的配置文件比如存档 mod修改一些不需要加密的二进制文件 3.4 测试
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ApplicationTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){Debug.Log(Application.dataPathApplication.dataPath);Debug.Log(Application.dataPathApplication.dataPath/Readme);Debug.Log(Application.persistentDataPathApplication.persistentDataPath);Debug.Log(Application.streamingAssetsPathApplication.streamingAssetsPath);}// Update is called once per framevoid Update(){}
}4 游戏持久化文件路径 persistentDataPath 可读可写 4.1 persistentDataPath
持久化文件路径persistentDataPath此属性用于返回一个持久化数据存储目录的路径(只读)可以在此路径下存储一下持久化的数据文件。对于同一平台在不同程序中调用此属性时其返回值是相同的但是在不同的运行平台下其返回值会不一样。 4.2 特点
可读可写可见不加密不压缩方便阅读和拷贝
存储的文职并不在 unity的项目的Assets这里了可以看到下面的测试结果这个persistantDataPath 是存储在C盘的。也是跨平台的 4.3 测试
Application.persistantDataPath //返回的就是unity现在项目的Assets目录游戏的配置都存储在这个文件路径下游戏存档在 Roaming下 using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ApplicationTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){Debug.Log(Application.dataPathApplication.dataPath);Debug.Log(Application.dataPathApplication.dataPath/Readme);Debug.Log(Application.persistentDataPathApplication.persistentDataPath);Debug.Log(Application.streamingAssetsPathApplication.streamingAssetsPath);}// Update is called once per framevoid Update(){}
}5 游戏的临时文件夹 Application.temporaryCachePath
5.1 Application.temporaryCachePath
temporaryCachePath此属性用于返回一个临时数据的缓存目录(只读)。对于同一平台在不同程序中调用此属性时其返回值是相同的但是在不同的运行平台下其返回值是不一样的。游戏读写文件时的临时的保存文件夹可能就是类缓存之类的吧 5.2 测试
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ApplicationTest : MonoBehaviour
{// Start is called before the first frame updatevoid Start(){Debug.Log(Application.dataPathApplication.dataPath);Debug.Log(Application.dataPathApplication.dataPath/Readme);Debug.Log(Application.persistentDataPathApplication.persistentDataPath);Debug.Log(Application.streamingAssetsPathApplication.streamingAssetsPath);Debug.Log(Application.temporaryCachePathApplication.temporaryCachePath);}// Update is called once per framevoid Update(){}
}