首页 > 编程知识 正文

unity3d有手机版吗,unity3d资源包

时间:2023-05-03 12:46:48 阅读:141246 作者:4140

转自:原文地址 一.各平台上的资源目录 Unity3D目录: Application.dataPath此属性用于返回程序数据文件所在文件夹的路径。 例如,在phdhy中是资产。 application.streamingassetspath此属性用于返回流数据的缓存目录。 返回路径是相对路径,适用于设置外部数据文件的路径。 Application.persistentDataPath此属性用于返回存储持久性数据文件的持久性数据存储目录的路径。 Application.temporaryCachePath此属性用于返回临时数据的缓存目录。 2.Android平台: application.datapath/data/app/XXX.XXX.apk application.streamingassetspathjar : file :///data/aata/apk data/XXX.XXX /文件应用程序. temporarycachepath/data/data 3.IOS平台: APP.datapath APP /xxxxx

xxx-xxxx-xxxx-xxxx-

总结:

同样,只读不可写。主要用来存放二进制文件。只能用过WWW类来读取。

AssetBundle:

关于AssetBundle的介绍已经有很多了。简而言之就是把prefab或者二进制文件封装成AssetBundle文件(也是一种二进制)。但是也有硬伤,就是在移动端无法更新脚本。下面简单的总结下:

是Unity3D定义的一种二进制类型。最好将prefab封装成AseetBundle,不过上面不是才说了在移动端无法更新脚本吗?那从Assetbundle中拿到的Prefab上挂的脚本是不是就无法运行了?也不一定,只要这个prefab上挂的是本地脚本,就可以。使用WWW类来下载。

PersistentDataPath:

看上去它只是个路径呀,可为什么要把它从路径里面单独拿出来介绍呢?因为它的确蛮特殊的,这个路径下是可读写。而且在IOS上就是应用程序的沙盒,但是在Android可以是程序的沙盒,也可以是sdcard。并且在Android打包的时候,ProjectSetting页面有一个选项Write Access,可以设置它的路径是沙盒还是sdcard。下面同样简单的总结一下:

内容可读写,不过只能运行时才能写入或者读取。 提前将数据存入这个路径是不可行的。无内容限制。你可以从  StreamingAssets 中读取二进制文件或者从 AssetBundle读取文件来写入 PersistentDataPath 中。写下的文件,可以在电脑上查看。同样也可以清掉。
案例: 1.Resources: _result = Resources.Load(path).ToString();     2.StreamingAssets:

using UnityEngine;using System.Collections;using EggToolkit;using System.Xml.Linq;using System.Xml;using System.IO;public class Test : MonoBehaviour { private string _result; // Use this for initialization void Start () { StartCoroutine(LoadXML()); } // Update is called once per frame void Update () { } /// <summary> /// 如前文所述,streamingAssets只能使用www来读取, /// 如果不是使用www来读取的同学,就不要问为啥读不到streamingAssets下的内容了。 /// 这里还可以使用了persistenDataPath来保存从streamingassets那里读到内容。 /// </summary> IEnumerator LoadXML() { string sPath= Application.streamingAssetsPath + "/Test.xml"; WWW www = new WWW(sPath); yield return www; _result = www.text; } void OnGUI() { GUIStyle titleStyle = new GUIStyle(); titleStyle.fontSize = 20; titleStyle.normal.textColor = new Color(46f/256f, 163f/256f, 256f/256f, 256f/256f); GUI.Label(new Rect(400, 10, 500, 200), _result,titleStyle); }}   3.AssetBundle:

//从AssetBundle中读取xmlusing EggToolkit;using System.Xml.Linq;using System.Xml;using System.IO;public class Test : MonoBehaviour { private string _result; // Use this for initialization void Start () { LoadXML(); } // Update is called once per frame void Update () { } void LoadXML() { AssetBundle AssetBundleCsv = new AssetBundle(); //读取放入StreamingAssets文件夹中的bundle文件 string str = Application.streamingAssetsPath + "/" + "TestXML.bundle"; WWW www = new WWW(str); www = WWW.LoadFromCacheOrDownload(str, 0); AssetBundleCsv = www.assetBundle; string path = "Test"; TextAsset test = AssetBundleCsv.Load(path, typeof(TextAsset)) as TextAsset; _result = test.ToString(); } void OnGUI() { GUIStyle titleStyle = new GUIStyle(); titleStyle.fontSize = 20; titleStyle.normal.textColor = new Color(46f/256f, 163f/256f, 256f/256f, 256f/256f); GUI.Label(new Rect(400, 10, 500, 200), _result,titleStyle); }}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。