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 本地数据存储的更多相关文章

  1. Android本地数据存储复习

    Android本地数据存储复习 Android无论是应用层还是系统层都需要在本地保存一些数据,尤其在应用层中使用的就更为普遍,大体有这么几种:SharedPreference,file,sqlite数 ...

  2. iOS开发——数据持久化&使用NSUserDefaults来进行本地数据存储

    使用NSUserDefaults来进行本地数据存储   NSUserDefaults适合存储轻量级的本地客户端数据,比如记住密码功能,要保存一个系统的用户名.密码.使用NSUserDefaults是首 ...

  3. iOS APP之本地数据存储(译)

    最近工作中完成了项目的用户信息本地存储,查阅了一些本地存储加密方法等相关资料.期间发现了一个来自印度理工学院(IIT)的信息安全工程师的个人博客,写了大量有关iOS Application secur ...

  4. Windows 8 应用开发 - 本地数据存储

    原文:Windows 8 应用开发 - 本地数据存储      在应用中通常会遇到用户主动或被动存储信息的情况,当应用关闭后这些数据仍然会存储在本地设备上,用户下次重新激活应用时会自动加载这些数据.下 ...

  5. iOS开发技术分享(1)— iOS本地数据存储

    iOS开发技术分享(1)— iOS本地数据存储 前言: 我本是一名asp.net程序员,后来加入了iOS游戏开发队伍,到现在也有一年多的时间了.这一年来,每天都干到2.3点钟才睡觉,不为别的,只为了学 ...

  6. 浏览器本地数据存储解决方案以及cookie的坑

    本地数据存储解决方案以及cookie的坑 问题: cookie过长导致页面打开失败 背景: 在公司的项目中有一个需求是打开多个工单即在同一个页面中打开了多个tab(iframe),但是需要在刷新时只刷 ...

  7. Android之ListView,AsyncTask,GridView,CardView,本地数据存储,SQLite数据库

    版权声明:未经博主允许不得转载 补充 补充上一节,使用ListView是用来显示列表项的,使用ListView需要两个xml文件,一个是列表布局,一个是单个列表项的布局.如我们要在要显示系统所有app ...

  8. cocos2d-html5开发之本地数据存储

    做游戏时常常须要的一个功能呢就是数据的保存了,比方游戏最高分.得到的金币数.物品的数量等等.cocos2d-html5使用了html5.所以html5的数据保存方法是对引擎可用的: html5本地数据 ...

  9. 本地数据存储解决方案以及cookie的坑

    本地数据存储解决方案以及cookie的坑 问题: cookie过长导致页面打开失败 背景: 在公司的项目中有一个需求是打开多个工单即在同一个页面中打开了多个tab(iframe),但是需要在刷新时只刷 ...

随机推荐

  1. os.popen(command)

    command="/usr/local/sbin/xxx_cmd" os.popen(command) xxx_cmd是自己编译的二进制文件,如果不加上全路径/usr/local/ ...

  2. Nginx学习笔记(六) 源码分析&启动过程

    Nginx的启动过程 主要介绍Nginx的启动过程,可以在/core/nginx.c中找到Nginx的主函数main(),那么就从这里开始分析Nginx的启动过程. 涉及到的基本函数 源码: /* * ...

  3. iOS之富文本

    之前做项目时遇到一个问题: 使用UITextView显示一段电影的简介,由于字数比较多,所以字体设置的很小,行间距和段间距也很小,一大段文字挤在一起看起来很别扭,想要把行间距调大,结果在XCode中查 ...

  4. iOS开发-UITextView根据内容自适应高度

    UITextView作为内容文本输入区域,有的时候我们需要根据内容动态改变文本区域的高度,效果如下: 定义UITextView,实现UITextViewDelegate: -(UITextView * ...

  5. android 多布局

    做为最后的方法,也是最后一个才会考虑的方法,那就是为不同的尺寸界面单独写布局.不到万不得已不要用这个方法,相信不少人和我一样都被逼着用过这个方法吧.需要说明的是,横竖屏切换使用不同布局也是用这个方法解 ...

  6. Android中的IOC框架,完全注解方式就可以进行UI绑定和事件绑定

    转载请注明出处:http://blog.csdn.net/blog_wang/article/details/38468547 相信很多使用过Afinal和Xutils的朋友会发现框架中自带View控 ...

  7. android: SQLite 数据库的最佳实践

    6.5.1    使用事务 前面我们已经知道,SQLite 数据库是支持事务的,事务的特性可以保证让某一系列的操 作要么全部完成,要么一个都不会完成.那么在什么情况下才需要使用事务呢?想象以下场 景, ...

  8. SQL Server查看所有表大小、表行数和占用空间信息

    一.查看表名和对应的数据行数select  a.name as '表名',b.rows as '表数据行数'from sysobjects a inner join sysindexes bon a. ...

  9. Solr DataImportHandler

    1.参数clean clean : (default 'true'). Tells whether to clean up the index before the indexing is start ...

  10. redis一句话