Esempio n. 1
0
    public void ShowOneMatchRecord(int recordIndex)
    {
        var dirIndex = recordIndex;

        recordIndex--;                                                                                      //从1开始,变成从0开始
        m_allRecords[recordIndex].Init();
        m_allRecords[recordIndex].dirStr = PlayerPrefs.GetString(string.Format("RecordFile{0}", dirIndex)); //存档文件夹
        DirectoryInfo dirInfo    = new DirectoryInfo(m_allRecords[recordIndex].dirStr);
        var           fileInfo   = dirInfo.GetFiles();
        int           replyCount = fileInfo.Length;

#if UNITY_IOS || UNITY_ANDROID
        replyCount -= 5;
#else
        replyCount -= 1;
#endif
        FileStream fInfo    = new FileStream(string.Format("{0}/recordInfo.save", m_allRecords[recordIndex].dirStr), FileMode.Open);
        var        bwReader = new BinaryReader(fInfo);

        m_allRecords[recordIndex].Init();
        m_allRecords[recordIndex].roomID       = bwReader.ReadInt32();
        m_allRecords[recordIndex].createUserID = bwReader.ReadUInt32();
        m_allRecords[recordIndex].totalCount   = bwReader.ReadInt32();
        m_allRecords[recordIndex].localUserID  = bwReader.ReadInt32();

        Debug.Log("roomID " + m_allRecords[recordIndex].roomID + "createuserID " + m_allRecords[recordIndex].createUserID + " count " + m_allRecords[recordIndex].totalCount
                  + " local user is " + m_allRecords[recordIndex].localUserID);

        var typeValue = typeof(UserInfoStruct);
        var typeSize  = Marshal.SizeOf(typeValue);
        for (int i = 0; i < 4; i++)
        {
            var buf = bwReader.ReadBytes(typeSize);
            m_allRecords[recordIndex].userInfo[i] = (UserInfoStruct)StructConverterByteArray.BytesToStruct(buf, typeValue);
        }
        m_allRecords[recordIndex].ScorePerMatch  = new long[replyCount, 4];
        m_allRecords[recordIndex].matchStartTime = new string[replyCount];
        for (int i = 0; i < replyCount; i++)
        {
            m_allRecords[recordIndex].matchStartTime[i] = bwReader.ReadString();
            for (int j = 0; j < 4; j++)
            {
                m_allRecords[recordIndex].ScorePerMatch[i, j] = bwReader.ReadInt64();
                m_allRecords[recordIndex].ScoreTotal[j]      += m_allRecords[recordIndex].ScorePerMatch[i, j];
            }
        }
        bwReader.Close();
        fInfo.Close();
    }
Esempio n. 2
0
    //gameend 消息,存储当局分数等信息到recordInfo.save文件内
    //解散时data为空,当前局所有玩家得分为0
    public void StopRecord(byte[] data = null, int datasize = 0)
    {
        Debug.LogError("StopRecord");
        return;

        if (!bRecording)
        {
            return;
        }

#if UNITY_STANDALONE
        if (HNGameManager.m_iLocalChairID != 0)
        {
            return;
        }
#endif
        for (int i = 0; i < msgQueue.Count; i++)
        {
            msgQueue[i].WriteData(bwWriter);
        }
        bwWriter.Flush();
        bwWriter.Close();
        fs.Close();
        var trueRecord = CurrentRecordCount;
        if (CurrentRecordCount > MaxRecordCount)
        {
            trueRecord = (CurrentRecordCount % (MaxRecordCount + 1)) + 1;
        }
        var        dirStr = PlayerPrefs.GetString(string.Format("RecordFile{0}", trueRecord));//存档文件夹
        FileStream fInfo  = new FileStream(string.Format("{0}/recordInfo.save", dirStr), FileMode.Append);
        bwWriter = new BinaryWriter(fInfo);

        var kernel = (GameScene)CServerItem.get().GetClientKernelSink();
        for (int i = 0; i < savedUserInfoData.Length; i++)
        {
//#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
//            string filename = string.Format("{0}/{1}.png", dirStr, savedUserInfoData[i].IUserId);
//            if (File.Exists(filename) == false)
//            {
//                if (HNGameManager.userId2HeadImageDirectory.ContainsKey(savedUserInfoData[i].IUserId))
//                {
//                    var sprite = HNGameManager.userId2HeadImageDirectory[savedUserInfoData[i].IUserId];
//                    Loom.QueueOnMainThread(() =>
//                    {
//                        var buf = sprite.texture.EncodeToPNG();
//                        File.WriteAllBytes(filename, buf);
//                    });
//                }
//            }
//#endif
        }

        if (data == null)
        {
            Debug.Log("----------write 0 to file1111");
            for (int i = 0; i < 4; i++)
            {
                bwWriter.Write((long)(0));
            }
        }
        else
        {
            var           typeValue = typeof(CMD_S_GameEnd);
            CMD_S_GameEnd pGameEnd  = (CMD_S_GameEnd)StructConverterByteArray.BytesToStruct(data, typeValue);
            //bwWriter.Write(pGameEnd.lGameScore[HNGameManager.m_iLocalChairID]);
            //Debug.Log("-------------Write score to file: " + pGameEnd.lGameScore[HNGameManager.m_iLocalChairID]);
            //var curPlayerChairID = HNGameManager.getNextPlayerChairID(HNGameManager.m_iLocalChairID);
            //int iIndex = 1;
            //while (curPlayerChairID != HNGameManager.m_iLocalChairID)
            //{
            //    bwWriter.Write(pGameEnd.lGameScore[curPlayerChairID]);
            //    Debug.Log("-------------Write score to file: " + pGameEnd.lGameScore[curPlayerChairID]);
            //    curPlayerChairID = HNGameManager.getNextPlayerChairID(curPlayerChairID);
            //}
        }
        bwWriter.Flush();
        bwWriter.Close();
        fInfo.Close();

        bRecording = false;
        msgQueue.Clear();
        userInfoStorages = null;
    }