首页 > 代码库 > Unity3D 相关项目代码
Unity3D 相关项目代码
一、Application.PresistentDataPath
注意最后面是没有/的
public static string PresistentDataPathForEditor = "C:/Users/Administrator/AppData/LocalLow/DefaultCompany/工程名"; public static string PresistentDataPathForAndroid = "/mnt/sdcard/Android/data/包名/files";
二、序列化与反序列化
[Serializable]public class CategoryBean { public string Name; static string FileName { get { return Application.persistentDataPath + "/category.dat"; } } public static void Load() { Global.Category = new CategoryBean(); if (File.Exists(FileName)) { try { using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read)) { BinaryFormatter b = new BinaryFormatter(); Global.Category = (CategoryBean)b.Deserialize(fs); } } catch (Exception ex) { Debuger.Log("Globals.load occurs an error:" + ex); } } else{ Debuger.Log("Local file is null"); } } public static void Save() { if (Global.Category == null) return; try { using (FileStream fs = new FileStream(FileName, FileMode.Create, FileAccess.Write)) { BinaryFormatter b = new BinaryFormatter(); b.Serialize(fs, Global.Category); } } catch (Exception ex) { Debuger.Log("Globals.Save occurs an error:" + ex); } }}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。