http://www.cnblogs.com/solq/archive/2012/05/21/2511522.html



TextAsset t = (TextAsset)Resources.Load("skill2");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(t.text.ToString().Trim()); XmlElement n = (XmlElement)xmlDoc.SelectSingleNode("/datas/data[@skillID='1002']");
if (n != null)
{
print("+++++++++++++++++++++++++++++++++++++++++++++++++");
data += n.GetAttribute("skillID");
}

解决 unity 生成 android apk read Resources

试了很多方法都找不到 unity 的目录,,最后没有办法了,放在 Resources 目录里。。。

发觉只能读不能写,,汗,,,白费了,又重新找。。。。

续:

http://forum.unity3d.com/threads/97043-Sqlite-for-Android-help-please/page2

http://forum.unity3d.com/threads/114660-Unity-3D-Android-SQLite-Examples

http://unity3d.com/support/documentation/Manual/StreamingAssets.html

找到了 android 工程模板了。。。。

Unity\Editor\Data\PlaybackEngines\androidplayer\

就像 web 模板一样

把它复制出来,导入eclipse

好了,只能拼 android 基础了。。。。

做好放在

资料:http://www.xuanyusong.com/archives/676

http://game.ceeger.com/Manual/Plugins.html

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

解决了,,,下面说下步骤

test.txt 路径如图

void readFile(string file)
{
path = "jar:file://" + Application.dataPath + "!/assets/" + file; if (File.Exists(path))
{
stringToEdit = "yes";
}
else
{
stringToEdit = "no"; WWW www = new WWW(path);
while (!www.isDone) { } stringToEdit += " " + www.text; }
}

不知道为什么 File.Exists(path)会检测不到文件,,,不过能读取就可以了

说下

Application.persistentDataPath 是指向 android /data/data/xxx.xxx.xxx/files/
Application.dataPath 是指向 /data/app/xxx.xxx.xxx.apk

汗:http://game.ceeger.com/Manual/StreamingAssets.html 这是unity圣典翻译好了,写得很详细了,,,
难怪会检测不到文件..现在还在解决解包问题
然后复制到 Application.persistentDataPath


/////////////////////////////////////最终方式/////////////////////////////////////////


using UnityEngine;
using System.Collections;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Core;
using System;
public class Test : MonoBehaviour
{
string path = "";
string zip_file = "d:\\t.zip";
void Start()
{
path = "jar:file://" + Application.dataPath + "!/assets/";
//readFile("test.txt"); // File.WriteAllText(Application.persistentDataPath + "/xx2.txt", "xxxxxxxxxxxxxxxxxxxx"); UnZipFile(Application.dataPath, "assets"); } #region 解压资料处理fn //判断是否已经解压
bool checkDecompressingFiles(string flag_file)
{
if (!File.Exists(Application.persistentDataPath + "/" + flag_file))
{
File.WriteAllText(Application.persistentDataPath + "/" + flag_file, "a");
return false;
}
return true;
} /*
* 没有测试过
ICSharpCode.SharpZipLib.Zip.FastZip zip = new ICSharpCode.SharpZipLib.Zip.FastZip();
zip.CreateZip("C:\\foo.zip", "C:\\待压缩的文件夹", true, ""); //第三个参数表示是否压缩子文件夹
zip.ExtractZip("C:\\foo.zip", "C:\\压缩后存放的文件夹", "");
如果我们只想压缩目录中的一个或部分文件,或者我们只想解压文件中的一个或部分文件,怎么办呢?那就得把最后一个参数用上,它是字符串类型的正则表达式,比如只压缩 ini 文件用:"^.*(.ini)$"。
*/ //用第三方工具去读取 zip
void UnZipFile(string zipFilePath,string dir)
{
if (checkDecompressingFiles("init.txt")) {
stringToEdit += " 已经解压过了";
return;
}else
stringToEdit += " 第一次解压";
using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath)))
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
// print("directoryName:" + directoryName);
// print("fileName:" + fileName); if (directoryName.Length > 0 && directoryName.Contains(dir))
{
//stringToEdit += " directoryName:" + directoryName+"\n";
Directory.CreateDirectory(Application.persistentDataPath + "/" + directoryName);
if (fileName != string.Empty)
{
using (FileStream streamWriter = File.Create(Application.persistentDataPath + "/" + theEntry.Name))
{ int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
streamWriter.Write(data, 0, size);
else
break;
}
}
}
} }
}
} //没有测试过下面
void CreateZipFile(string filesPath, string zipFilePath)
{ if (!Directory.Exists(filesPath))
{ return;
} try
{
string[] filenames = Directory.GetFiles(filesPath);
using (ZipOutputStream s = new ZipOutputStream(File.Create(zipFilePath)))
{ s.SetLevel(9); // 压缩级别 0-9
//s.Password = "123"; //Zip压缩文件密码
byte[] buffer = new byte[4096]; //缓冲区大小
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
//entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
s.Finish();
s.Close();
}
}
catch (Exception ex)
{ }
} //直接用 unty www 去读取 jar 跟 zip 标准差不多吧
void readFile(string file)
{
path+= file; if (File.Exists(path))
{
stringToEdit = "yes";
}
else
{
stringToEdit = "no"; WWW www = new WWW(path);
while (!www.isDone) { } stringToEdit += " " + www.text; stringToEdit+=" ReadAllText:"+File.ReadAllText(path);
}
}
#endregion //请输入一个字符串
private string stringToEdit = ""; void Update ()
{
//点击手机返回键关闭应用程序
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home) )
{
Application.Quit();
}
} void OnGUI()
{ GUILayout.TextField("persistentDataPath:" + Application.persistentDataPath);
GUILayout.TextField("dataPath:" + Application.dataPath);
GUILayout.TextField("temporaryCachePath:" + Application.temporaryCachePath); stringToEdit = GUILayout.TextArea (stringToEdit, GUILayout.Width(300),GUILayout.Height(250));
} }
//用到解压的库。。。http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx
//感谢:雨松MOMO http://www.xuanyusong.com/
//示例demo http://files.cnblogs.com/solq/android_read_Resources.zip

解决 unity 生成 android apk read Resources的更多相关文章

  1. unity生成Android apk

    前提:本文默认你安装了unity5.6版本,不是这个版本的没有Gradle(new)选项,也默认你安装了Android Studio并配置好了环境变量. Gradle(new):打包Android S ...

  2. Xamarin 打包生成 Android apk 文件

    Visual Studio 支持 apk 发布 Xamarin.Forms项目或Xamarin.Android项目开发完成之后需要发布.比较常规的发布方式是生成 apk 文件,微软也考虑到开发者有发布 ...

  3. [RN] React Native 生成 Android APK

    在用模拟器或者真机调试完App后,需要将App打包成Apk发布文件. 下面简单记录下打包步骤: 第一:生成签名密钥 这一步的操作主要是生成需要的签名密钥,供android调用,生成的文件待用 在项目根 ...

  4. 已解决(转)关于android - apk(解析错误)解析程序包时出现问题

    如果开发的应用用户较多,那么必须保证应用在多个版本不同的设备上能够正确的运行.这就要求对各个版本比较熟悉,知道在什么版本中加入了什么新的功能或特性.但是Android的版本太多了,是个令人头疼的问题. ...

  5. [Unity] 导出Android APK包出错

    确认Android环境是OK的. 检查 StreamingAssets 目录下是否有中文的文件名 检查其它目录的中文文件名. 移除一些插件再试.

  6. Unity编译Android的原理解析和apk打包分析

    作者介绍:张坤 最近由于想在Scene的脚本组件中,调用Android的Activity的相关接口,就需要弄明白Scene和Activity的实际对应关系,并对Unity调用Android的部分原理进 ...

  7. Cordova打包vue项目生成Apk (解决cordova build android抛出的zip问题)

    最近对vue前端框架情有独钟.但研究了一下怎么把vue项目打包成android apk来玩玩. 首先讲一下创建vue2.x项目.其实在之前的文章中都有写过,有兴趣的同学可以去看看.http://www ...

  8. android studio 项目生成的apk变小的原因

    问题:感觉直接在apk文件夹下面拷出来的apk不能安装使用,而且apk比较小,可能就是这个问题引起的 Android Studio版本升级到2.3后,增加了instant run功能,对项目的buil ...

  9. Xamarin如何生成Android项目的APK

    Xamarin如何生成Android项目的APK 首先需要选择Release模式生成项目.然后从“生成”菜单中选择Export Android Package命令,就可以导出APK包.APK保存在An ...

随机推荐

  1. RYU改动监听port Mininet在custom自建拓扑和连接到指定控制器命令解释

    1.RYU控制器改动监听port 在ryu/ryu/ofproto以下的ofproto_common.py watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc ...

  2. window.onerror 错误监听,发到后台

    var doc = document.body || document.documentElement; var _onerror = Onerror(''); var Onerror = funct ...

  3. 手把手原生js轮播图

    在团队带人,突然被人问到轮播图如何实现,进入前端领域有一年多了,但很久没自己写过,一直是用大牛写的插件,今天就写个简单的适合入门者学习的小教程.当然,轮播图的实现原理与设计模式有很多种,我这里讲的是用 ...

  4. CentOS-7-64bit 下为firefox安装flashplayer

    最近更新了Centos 7 还是有一些不习惯的 给ff安flashplayer插件时,按centos 6.x的方法时都无法成功,后来find了一下,才知道firefox还有一个64bit的文件夹: 解 ...

  5. codeforces B. Calendar 解题报告

    题目链接:http://codeforces.com/problemset/problem/304/B 题目意思:给出两个日期,需要算出这两个日期之间有多少日. 细心模拟就可以了.特别要注意的是,两个 ...

  6. codevs 1012 最大公约数和最小公倍数问题

    题目描述 Description 输入二个正整数x0,y0(2<=x0<100000,2<=y0<=1000000),求出满足下列条件的P,Q的个数 条件:  1.P,Q是正整 ...

  7. ios系统的特点

    iOS优势 1). 比较稳定,因为他是一个完全封闭的系统,不开源,但是这个系统有他自己严格管理体系,比如app store的app应用:他有自己的评审规则,另外很多软件是需要收费的,这在一定程度上也说 ...

  8. 第九章-IO编程

    IO是输出输入的意思 在计算机中常用到的数据交换的地方是磁盘, 网络等 输入流是从外面(磁盘, 网络)流进内存 输出流是从内存流到外面(磁盘, 网络) 同步IO是指等待IO完成再继续执行 异步IO是在 ...

  9. 「AHOI2008」「LuoguP4281」紧急集合 / 聚会(LCA

    题目描述 欢乐岛上有个非常好玩的游戏,叫做“紧急集合”.在岛上分散有N个等待点,有N-1条道路连接着它们,每一条道路都连接某两个等待点,且通过这些道路可以走遍所有的等待点,通过道路从一个点到另一个点要 ...

  10. python3 分布式进程(跨机器)BaseManager(multiprocessing.managers)

    A机器负责发送任务和接受结果: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #ta ...