Beispiel #1
0
        public void Init()
        {
            try
            {
                // 查找XML,如果不存在就新建
                string path     = Application.dataPath + "/BCityAsset/";
                string filename = "data.xml";
                string p        = path + filename;

                bool isCreate = AppUtils.CreateFileIfNotExist(path, filename);
                if (isCreate)
                {
                    _likeDataBase = new PageRecordDataBase();
                    CreateXMLData();
                }
                else
                {
                }
                LoadDataFromXml();
            }
            catch (Exception e)
            {
                Debug.LogError(e.StackTrace);
                Debug.LogError(e.Message);
                //throw new Exception("服务器连接失败:" + e.Message.ToString());
            }
        }
Beispiel #2
0
        private void LoadDataFromXml()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(PageRecordDataBase));
            FileStream    stream     = new FileStream(Application.dataPath + "/BCityAsset/data.xml", FileMode.Open);

            _likeDataBase = serializer.Deserialize(stream) as PageRecordDataBase;
            stream.Close();
        }
Beispiel #3
0
        public void CreateXMLData()
        {
            Debug.Log("创建XML");

            XmlSerializer serializer = new XmlSerializer(typeof(PageRecordDataBase));
            string        path       = Application.dataPath + "/BCityAsset/data.xml";

            _likeDataBase = new PageRecordDataBase();

            FileStream stream = new FileStream(path, FileMode.Create);

            serializer.Serialize(stream, _likeDataBase);
            stream.Close();
        }