unity3d 本地数据存储
using UnityEngine;
using System.Collections;
//路径工具类
public class PathKit
{ /** 后缀常量字符 */
public const string SUFFIX = ".txt";
const string PREFIX="file://";
const string FORMAT=".unity3d";
public static string RESROOT=Application.persistentDataPath+"/"; public static string GetStreamingAssetsPath (string p_filename)
{
string _strPath = "";
if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer )
_strPath = "file://" + Application.streamingAssetsPath + "/" + p_filename + ".unity3d";
else if (Application.platform == RuntimePlatform.Android )
_strPath = Application.streamingAssetsPath + "/" + p_filename + ".unity3d";
else if ( Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.IPhonePlayer)
_strPath = "file://"+ Application.streamingAssetsPath + "/" + p_filename + ".unity3d"; return _strPath;
} public static string GetOSDataPath (string p_filename)
{
string path;
path = ""; if (Application.platform == RuntimePlatform.OSXEditor)
path = Application.persistentDataPath + p_filename; if (Application.platform == RuntimePlatform.IPhonePlayer)
path = RESROOT + p_filename; if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
path = Application.dataPath +"/cache/"+ p_filename; if (Application.platform == RuntimePlatform.Android)
path =RESROOT + p_filename; // Debug.LogWarning("===========path:"+path);
return path;
} public static string GetURLPath (string p_filename,bool needPreFix,bool needFormat)
{
string path;
path = ""; if (Application.platform == RuntimePlatform.OSXEditor)
path = Application.persistentDataPath+"/" + p_filename; if (Application.platform == RuntimePlatform.IPhonePlayer)
path = RESROOT + p_filename; if (Application.platform == RuntimePlatform.WindowsEditor)
path = Application.dataPath +"/cache/"+ p_filename; if (Application.platform == RuntimePlatform.WindowsPlayer)
path = Application.dataPath +"/cache/"+ p_filename; if (Application.platform == RuntimePlatform.Android)
path = RESROOT + p_filename; if(needPreFix) path=PREFIX+path;
if(needFormat) path=path+FORMAT;
//Debug.LogWarning("===========path:"+path);
return path;
} public static string getFileName(string path)
{ string[] _list= path.Split(new char[]{'/'}); if(_list.Length>) return _list[_list.Length-];
else
return ""; } public static string getFileDir(string path)
{
path = path.Replace("\\","/");
path = path.Substring(,path.LastIndexOf("/"));
return path;
} public static void CreateDirIfNotExists(string path)
{
string dir = getFileDir(path);
if(!System.IO.Directory.Exists(dir))
{
System.IO.Directory.CreateDirectory(dir);
}
} }
private void SaveFriendToLocal()
{
string cacheStr = "";//内容string path = PathKit.RESROOT + string.Format(CHAT_CACHE_DIR, UserId);
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
sw.BaseStream.Seek(, SeekOrigin.Begin);
sw.Write(cacheStr);
sw.Close();
}
private void LoadFriendFromLocal()
{
try
{
string path = PathKit.RESROOT + string.Format(CHAT_CACHE_DIR,UserId);
if (!File.Exists(path)) return;
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, , (int)fs.Length);
fs.Close();
mCacheFriend = new List<string> ();string[] arr = Encoding.UTF8.GetString (bytes).Split ('\n');
for (int i = ; i < arr.Length; i++) {
string[] item = arr[i].Split ('\t');
mCacheFriend.Add (item[]);
}
}
catch (System.Exception e)
{
Debug.Log(e.Message);
}
}
unity3d 本地数据存储的更多相关文章
- Android本地数据存储复习
Android本地数据存储复习 Android无论是应用层还是系统层都需要在本地保存一些数据,尤其在应用层中使用的就更为普遍,大体有这么几种:SharedPreference,file,sqlite数 ...
- iOS开发——数据持久化&使用NSUserDefaults来进行本地数据存储
使用NSUserDefaults来进行本地数据存储 NSUserDefaults适合存储轻量级的本地客户端数据,比如记住密码功能,要保存一个系统的用户名.密码.使用NSUserDefaults是首 ...
- iOS APP之本地数据存储(译)
最近工作中完成了项目的用户信息本地存储,查阅了一些本地存储加密方法等相关资料.期间发现了一个来自印度理工学院(IIT)的信息安全工程师的个人博客,写了大量有关iOS Application secur ...
- Windows 8 应用开发 - 本地数据存储
原文:Windows 8 应用开发 - 本地数据存储 在应用中通常会遇到用户主动或被动存储信息的情况,当应用关闭后这些数据仍然会存储在本地设备上,用户下次重新激活应用时会自动加载这些数据.下 ...
- iOS开发技术分享(1)— iOS本地数据存储
iOS开发技术分享(1)— iOS本地数据存储 前言: 我本是一名asp.net程序员,后来加入了iOS游戏开发队伍,到现在也有一年多的时间了.这一年来,每天都干到2.3点钟才睡觉,不为别的,只为了学 ...
- 浏览器本地数据存储解决方案以及cookie的坑
本地数据存储解决方案以及cookie的坑 问题: cookie过长导致页面打开失败 背景: 在公司的项目中有一个需求是打开多个工单即在同一个页面中打开了多个tab(iframe),但是需要在刷新时只刷 ...
- Android之ListView,AsyncTask,GridView,CardView,本地数据存储,SQLite数据库
版权声明:未经博主允许不得转载 补充 补充上一节,使用ListView是用来显示列表项的,使用ListView需要两个xml文件,一个是列表布局,一个是单个列表项的布局.如我们要在要显示系统所有app ...
- cocos2d-html5开发之本地数据存储
做游戏时常常须要的一个功能呢就是数据的保存了,比方游戏最高分.得到的金币数.物品的数量等等.cocos2d-html5使用了html5.所以html5的数据保存方法是对引擎可用的: html5本地数据 ...
- 本地数据存储解决方案以及cookie的坑
本地数据存储解决方案以及cookie的坑 问题: cookie过长导致页面打开失败 背景: 在公司的项目中有一个需求是打开多个工单即在同一个页面中打开了多个tab(iframe),但是需要在刷新时只刷 ...
随机推荐
- C语言宏高级用法 [总结]
1.前言 今天看代码时候,遇到一些宏,之前没有见过,感觉挺新鲜.如是上网google一下,顺便总结一下,方便以后学习和运用.C语言程序中广泛的使用宏定义,采用关键字define进行定义,宏只是一种简 ...
- [C++] 几行代码生成漂亮图片,数学家就是牛!
信息获得处:http://news.cnblogs.com/n/501488/ 分形:http://baike.baidu.com/subview/83243/11213590.htm?fr=alad ...
- 免费好用的web应用托管平台-续
上一篇博客给大家推荐了目前处于免费阶段的PAAS平台,可以托管各种应用,大家反响很不错,说明大家还是很需要和认可这个免费托管各种web应用的京东云擎平台.但是很多用户还是很担心未来可能还是会收费,对于 ...
- [备忘][转]rsync使用时的常见问题
sync使用时的常见问题: 错误1: rsync: read error: Connection reset by peer (104) rsync error: error in rsync pro ...
- [DOS] Net Use
Please use following command for regist a login user. net use \\server\folder [password] /user:[use ...
- Ubuntu 安装配置MySQL,并使用VS的Server Explorer UI界面远程管理MySQL
为安装配置方便,使用root账号登入Ubuntu. step1: 键入下面命令安装MySQL. 过程十分简单.安装过程中只需根据提示输入root账号的密码即可. step2:安装完成后检查MySQL是 ...
- paip.提升效率---request自动绑定domain object
paip.提升效率---request自动绑定domain object #.keyword,subtitle关键字,子标题 ------------------------- 复制request属性 ...
- paip.log4j 日志系统 参数以及最佳实践
paip.log4j 日志系统 参数以及最佳实践 %d{yyyy-MM-dd HH:mm:ss} [thrd:%t] %5p loger:%c (%C.%M.%L) - %m%n 201 ...
- PHP类与面向对象
PHP常量PHP常量大写PHP常量用define函数或const关键字定义一个常量一旦被定义,就不能再改变或者取消定义.在 PHP 5.3.0 以后,可以使用 const 关键字在类定义之外定义常量. ...
- [推荐] kylinPET是一款功能强大的性能测试工具
[推荐] kylinPET是一款功能强大的性能测试工具 官方网站: http://www.kylinpet.com/