示例#1
0
    private void ExcuteRecord()
    {
        if (GlobalData.m_pgrMgr != null)
        {
            PlayGameRecord pgr = GlobalData.m_pgrMgr.FindById(m_date);
            if (pgr != null)
            {
                GameItem gameItem = pgr.FindById(m_gameId);
                if (gameItem != null)
                {
                    gameItem.m_record.Add(tempRecordItem);
                    gameItem.m_count = gameItem.m_record.Count;
                }
                else
                {
                    gameItem            = new GameItem();
                    gameItem.m_gameId   = m_gameId;
                    gameItem.m_gameName = m_gameName;
                    gameItem.m_record   = new List <RecordItem>();
                    gameItem.m_record.Add(tempRecordItem);
                    gameItem.m_count = gameItem.m_record.Count;
                    pgr.m_gameItems.Add(gameItem);
                }
            }
            else
            {
                pgr             = new PlayGameRecord();
                pgr.m_date      = m_date;
                pgr.m_gameItems = new List <GameItem>();
                GameItem gameItem = new GameItem();
                gameItem.m_gameId   = m_gameId;
                gameItem.m_gameName = m_gameName;
                gameItem.m_record   = new List <RecordItem>();
                gameItem.m_record.Add(tempRecordItem);
                gameItem.m_count = gameItem.m_record.Count;
                pgr.m_gameItems.Add(gameItem);
                GlobalData.m_pgrMgr.m_dataList.Add(pgr);
            }
        }
        else
        {
            GlobalData.m_pgrMgr            = new PlayGameRecordMgr();
            GlobalData.m_pgrMgr.m_dataList = new List <PlayGameRecord>();
            PlayGameRecord pgr = new PlayGameRecord();
            pgr.m_date      = m_date;
            pgr.m_gameItems = new List <GameItem>();
            GameItem gameItem = new GameItem();
            gameItem.m_gameId   = m_gameId;
            gameItem.m_gameName = m_gameName;
            gameItem.m_record   = new List <RecordItem>();
            gameItem.m_record.Add(tempRecordItem);
            gameItem.m_count = gameItem.m_record.Count;
            pgr.m_gameItems.Add(gameItem);
            GlobalData.m_pgrMgr.m_dataList.Add(pgr);
        }

        XmlHelper.SaveXml("record.xml", GlobalData.m_pgrMgr, typeof(PlayGameRecordMgr), true);
        Debug.Log("record ok");
    }
示例#2
0
    void Start()
    {
        //write

        /*
         * GameItem item = new GameItem();
         * item.m_gameId = 1;
         * item.m_gameName = "游戏a";
         * item.m_record = new System.Collections.Generic.List<RecordItem>();
         * RecordItem ri1 = new RecordItem();
         * ri1.m_startTime = "08:00";
         * ri1.m_stopTime = "08:45";
         * ri1.m_duringTime = "45min";
         * RecordItem ri2 = new RecordItem();
         * ri2.m_startTime = "09:00";
         * ri2.m_stopTime = "09:45";
         * ri2.m_duringTime = "45min";
         * item.m_record.Add(ri1);
         * item.m_record.Add(ri2);
         * item.m_count = item.m_record.Count;
         *
         * PlayGameRecord pgr = new PlayGameRecord();
         * pgr.m_date = "2016-09-22";
         * pgr.m_gameItems = new System.Collections.Generic.List<GameItem>();
         * pgr.m_gameItems.Add(item);
         *
         * PlayGameRecordMgr pgrMgr = new PlayGameRecordMgr();
         * pgrMgr.m_dataList = new System.Collections.Generic.List<PlayGameRecord>();
         * pgrMgr.m_dataList.Add(pgr);
         *
         * XmlHelper.SaveXml("record.xml", pgrMgr, typeof(PlayGameRecordMgr));
         * Debug.Log("ok");
         */


        //read
        string            path   = Application.dataPath + "/Resources/Cfg/record.xml";
        PlayGameRecordMgr pgrMgr = XmlHelper.ParseXml <PlayGameRecordMgr>(path, typeof(PlayGameRecordMgr));

        string         date       = DateTime.Now.ToString("yyyy-MM-dd");
        PlayGameRecord recordItem = pgrMgr.FindById("2016-09-22");

        Debug.Log("count:" + recordItem.m_gameItems.Count);
        GameItem item = recordItem.FindById(1);//假设游戏id =1

        Debug.Log(item.m_gameName + "_" + item.m_count);
    }