Example #1
0
        public void Save(ref LusuoStream ls)
        {
            //Debug.Log("模型自身保存数据");
            ls.WriteInt(m_resID);
            ls.WriteString(m_strName);
            ls.WriteVector3(m_vPos.x, m_vPos.y, m_vPos.z);
            ls.WriteVector3(m_vRotate.x, m_vRotate.y, m_vRotate.z);
            ls.WriteVector3(m_vScale.x, m_vScale.y, m_vScale.z);
            ls.WriteBool(m_bStatic);

            // 读取子模型个数,遍历写入个数,索引,和偏移
            ls.WriteInt(m_lightMapIndexNum);
            for (int i = 0; i < m_lightMapIndexNum; i++)
            {
                ls.WriteInt(m_lightMapIndex[i]);
            }
            for (int i = 0; i < m_lightMapIndexNum; i++)
            {
                ls.WriteVector4(ref m_lightMapScaleOffset[i]);
            }
            // 写入环境音效
            ls.WriteInt(m_envSoundNum);
            for (int i = 0; i < m_envSoundNum; i++)
            {
                ls.WriteInt(m_envSoundResId[i]);
            }
        }
Example #2
0
        /// <summary>
        /// 消息发送时的内部方法,将逻辑结构体数据存放到ls中
        /// 子类无需重载
        /// </summary>
        public void SetByte <T>(T t, ref LusuoStream ls)
        {
            ls.WriteInt(0);           // 预留总字节数
            ls.WriteUShort(msgID);    // 写消息编号
            ls.WriteInt(eno);         // 写eno
            byte[] bytes = ProtobufHelper.Serialize <T>(t);
            ls.Write(ref bytes);      // 写具体结构体
            ls.Seek(0);
            // 内容字节数
            int contentLen = StringHelper.s_ShortSize + StringHelper.s_IntSize + bytes.Length;

            ls.WriteInt(contentLen);                         // 再次写内容长度
            msgMaxLen = StringHelper.s_IntSize + contentLen; // 长度字节数 + 内容字节数
        }
Example #3
0
        public void SendMessage <T>(ushort msgID, T t)
        {
            LusuoStream stream = new LusuoStream(new byte[m_uBufferSize]);

            stream.WriteInt(0);                  // 预留总字节数
            stream.WriteUShort(msgID);           // 写消息编号
            stream.WriteInt(1);
            byte[] bytes = ProtobufHelper.Serialize <T>(t);
            stream.Write(ref bytes);              // 写具体结构体
            stream.Seek(0);
            // 内容字节数
            int contentLen = StringHelper.s_ShortSize + StringHelper.s_IntSize + bytes.Length;

            stream.WriteInt(contentLen);                            // 再次写内容长度
            stream.m_byteLen = StringHelper.s_IntSize + contentLen; // 长度字节数 + 内容字节数

            _m_listMsg.Add(stream);
        }
Example #4
0
    private static bool ProcessCsvFile(DirectoryInfo folder)
    {
        DirectoryInfo[] dirInfo = folder.GetDirectories();
        foreach (DirectoryInfo item in dirInfo)
        {
            if (item.Name.Contains(".svn"))
            {
                continue;
            }
            ProcessCsvFile(item);
        }
        FileInfo[] fileInfo = folder.GetFiles();
        foreach (FileInfo item in fileInfo)
        {
            string postfix = ".csv";
            int    iPos    = item.Name.IndexOf(postfix, 0);
            if (iPos != -1 && iPos + postfix.Length == item.Name.Length)
            {
                string csvName = item.Name.ToLower().Replace(".csv", "");
                // 如果这个表没有写入到LogicSystem中,就不需要打包
                if (CsvManager.Inst.GetType(csvName) == (int)eAllCSV.eAC_None)
                {
                    Debug.LogWarning(item.Name + " 没有写入到LogicSystem中,是否为客户端不需要的表格?");
                    continue;
                }
                FileStream file;
                try
                {
                    file = new FileStream(item.FullName, FileMode.Open);
                    if (file == null)
                    {
                        Debug.LogError(item.Name + "处理失败。");
                    }
                }
                catch (IOException ioe)
                {
                    Debug.LogError("处理csv失败,检查是否已经打开:" + item.FullName + " " + ioe);
                    EditorUtility.DisplayDialog(
                        "打包配置错误",
                        "请关闭配置表,重新打包: " + item.FullName,
                        "确定");
                    file        = null;
                    m_csvStream = null;
                    return(false);
                }

                m_csvNums++;
                // 这里存csv的id效率更好
                //m_csvStream.WriteString(ref csvName);
                int type = (int)CsvManager.Inst.GetType(csvName);
                m_csvStream.WriteInt(type);

                byte[] readData = new byte[file.Length];
                file.Read(readData, 0, (int)file.Length);
                // 转码并写入到流
                readData = Encoding.Convert(Encoding.Default, Encoding.UTF8, readData);
                m_csvStream.WriteInt((int)readData.Length);
                m_csvStream.Write(ref readData);
                Debug.Log("处理配置表:" + item.Name);
            }
        }
        return(true);
    }
Example #5
0
    private static void ProcessResBytes()
    {
        m_resInfoCsv     = new AllResInfoCsv();
        m_mapNameResInfo = new Dictionary <string, ResInfo>(); // 下面批处理文件时,处理一个加一个,会审核是否有重复资源
        m_lstResinfo     = new List <ResInfo>();               // 保持时使用的数据
        m_setUseList     = new HashSet <int>();                // 存资源id
        m_curResID       = 0;

        bool b = m_resInfoCsv.Load(m_resCsvPath, Encoding.Default);

        if (!b)
        {
            Debug.LogError("注意: 资源总表,打开csv失败。");
            return;
        }

        foreach (ResInfo key in m_resInfoCsv.m_lstResinfo)
        {
            m_setUseList.Add(key.nResID);
        }

        string strFull = Path.GetDirectoryName(m_resPath);

        Directory.CreateDirectory(strFull);

        // 然后处理该文件夹中所有的文件
        ProcessResFile(new DirectoryInfo(m_resPath));

        // 然后遍历原始资源表列表,将无资源的预留id也写入到资源列表
        foreach (ResInfo oldItem in m_resInfoCsv.m_lstResinfo)
        {
            bool bHave = false;
            foreach (ResInfo newItem in m_lstResinfo)
            {
                if (oldItem.nResID == newItem.nResID)
                {
                    bHave = true;
                }
            }
            // 如果新的不包含,就加到新的
            if (!bHave)
            {
                oldItem.iType  = ResType.None;
                oldItem.strUrl = "";
                if (m_mapNameResInfo.ContainsKey(oldItem.strName))
                {
                    Debug.LogError("总资源表含有重复的资源:" + oldItem.strName);
                    continue;
                }
                m_mapNameResInfo.Add(oldItem.strName, oldItem);
                m_lstResinfo.Add(oldItem);
            }
        }

        m_resInfoCsv.Clear();
        m_resInfoCsv.m_mapNameResInfo = m_mapNameResInfo;
        m_resInfoCsv.m_lstResinfo     = m_lstResinfo;

        // 保存资源总配置文件
        m_resInfoCsv.Save("", Encoding.Default, true);

        // 生成二进制文件
        FileStream stream =
            new FileStream(m_resBytesPath, FileMode.Create);
        LusuoStream ls    = new LusuoStream(stream);
        int         iNums = m_lstResinfo.Count;

        ls.WriteInt(iNums);                     // 将真的资源个数写入到流的开始位置
        Debug.Log("成功写入资源个数:" + iNums);
        foreach (KeyValuePair <string, ResInfo> item in m_mapNameResInfo)
        {
            item.Value.Save(ref ls);
        }
        ls.Close();
    }