/// <summary> /// 初始化数据库连接 / xml 连接 /// </summary> public void InitData() { // CONNECT try { // 查找XML,如果不存在就新建 string path = Application.dataPath + "/MagicWallAsset/"; string filename = "like_data.xml"; string p = path + filename; bool isCreate = AppUtils.CreateFileIfNotExist(path, filename); if (isCreate) { _likeDataBase = new LikeDataBase(); SaveLikes(); } LoadLikes(); } catch (Exception e) { Debug.LogError(e.StackTrace); Debug.LogError(e.Message); throw new Exception("服务器连接失败:" + e.Message.ToString()); } }
// load function private void LoadLikes() { XmlSerializer serializer = new XmlSerializer(typeof(LikeDataBase)); FileStream stream = new FileStream(Application.dataPath + "/MagicWallAsset/like_data.xml", FileMode.Open); _likeDataBase = serializer.Deserialize(stream) as LikeDataBase; stream.Close(); }