码迷,mamicode.com
首页 > 其他好文 > 详细

Unity3D 相关项目代码

时间:2014-08-21 16:36:54      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:des   android   style   blog   http   color   os   io   

一、Application.PresistentDataPath

 注意最后面是没有/的

bubuko.com,布布扣
        public static string PresistentDataPathForEditor = "C:/Users/Administrator/AppData/LocalLow/DefaultCompany/工程名";
        public static string PresistentDataPathForAndroid = "/mnt/sdcard/Android/data/包名/files";
View Code

 

二、序列化与反序列化

bubuko.com,布布扣
[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);
       }
   }
}
View Code

 

Unity3D 相关项目代码,布布扣,bubuko.com

Unity3D 相关项目代码

标签:des   android   style   blog   http   color   os   io   

原文地址:http://www.cnblogs.com/chongxin/p/3927152.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!