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. [J2ME] 基本框架框架

    import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import jav ...

  2. Sale.js——快速创建促销样式

    小菜编写的又一款jQuery小插件,有兴趣的朋友可以试试~ 简介: 对于一个用于产品展示.销售的网站而言,很可能需要一种促销的特效. 一般而言,我们会在商品图片前加一个促销栏,写上一些促销标语.原价. ...

  3. Counting-Sort

    Counting-Sort(A,B,k) let C[0..k] be a new array for i = 0 to k C[i] = 0 for j = 1 to A.length C[A[j] ...

  4. 工作圈redis 使用

    redis作为内存数据库,更多的是作为内存cache来使用. 再所负责的工作圈中的使用,主要是分两方面: 1.数据对象: 主题的内容存储 主题回复内容的存储 用户信息存储 圈子信息存储 2.各数据对象 ...

  5. 转载: Qt 学习之路 2归档

    Qt 学习之路 2归档 http://www.devbean.net/2012/08/qt-study-road-2-catelog/

  6. Paip.最佳实践-- Buildin variale 内建变量 ,魔术变量,预定义变量,系统常量,系统变量 1

    Paip.最佳实践-- Buildin variale 内建变量 ,魔术变量,预定义变量,系统常量,系统变量 1.1.1       C++内建变量(__LINE__).... 1.1.2       ...

  7. ubuntu上安装mysql 编译安装

    为什么要折腾?首先说明的是ubuntu上安装mysql等软件是非常容易简单的,其简单的程度盖过windows上的安装,一句sudo apt-get install就可以搞定.如果想用最简便的方法安装m ...

  8. jQuery实现左移右移

    <html> <head> <meta charset="utf-8"> <title>完成左移右移</title> & ...

  9. spring源码 — 三、AOP代理生成

    AOP代理生成 AOP就是面向切面编程,主要作用就是抽取公共代码,无侵入的增强现有类的功能.从一个简单的spring AOP配置开始: <?xml version="1.0" ...

  10. 字符串匹配的KMP算法——Python实现

    #! /usr/bin/python # coding=utf-8 """ 基于这篇文章的python实现 http://blog.sae.sina.com.cn/arc ...