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),但是需要在刷新时只刷 ...
随机推荐
- 第十二章:Android数据存储(下)
一.SQLite介绍 提到数据存储问题,数据库是不得不提的.数据库是用来存储关系型数据的不二利器.Android为开发者提供了强大的数据库支持,可以用来轻松地构造基于数据库的应用.Android的数据 ...
- php 获取中文字符拼音首字母
//php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){return '';} $fchar=ord($str{}); }); ...
- JfreeChart使用(转载)
http://www.cnblogs.com/xingyun/ http://www.huosen.net/archives/156.html(此篇除了struts2外,还介绍了servlet下Jfr ...
- JS练习题2共8题
<p>1 打印出1-100里所有的偶数</p> <script> // for(var i=1;i<=100;i++){ // if(i%2==0){ // ...
- vc个版本对应的vs版本
VC6VC7(2003)VC8(2005)VC9(2008)VC10(2010)VC11(2012)VC12(2013)VC14(2015)
- 苹果App部署HTTPS进行在线下载安装
苹果App的ipa下载需要有几个前提,可参考:Android和IOS的本地App如何安装(apk&ipa) 本文主要介绍如何部署https提供ipa的下载,步骤如下: 1. 搭建一个HTTPS ...
- iptables防火墙原理详解
1. netfilter与iptables Netfilter是由Rusty Russell提出的Linux 2.4内核防火墙框架,该框架既简洁又灵活,可实现安全策略应用中的许多功能,如数据包过滤.数 ...
- Ubuntu “无法获得锁”解决方案(E: 无法获得锁 /var/cache/apt/archive
Ubuntu “无法获得锁”解决方案(E: 无法获得锁 /var/cache/apt/archive 现象一: E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源 ...
- 都昌 DCWriter电子病历编辑器演示文档截屏
- 隐藏nginx 版本号信息
为了安全,想将http请求响应头里的nginx版本号信息隐藏掉: 1. nginx配置文件里增加 server_tokens off; server_tokens作用域是http server loc ...