/// <summary>
        /// 将一个组中所有的xml数据加到数据库中
        /// </summary>
        /// <param name="stream">该组的数据流</param>
        /// <param name="addedXmls">从组中加到数据库中的所有xml名称</param>
        /// <returns>组名称,若添加失败或该组已存在,则返回null</returns>
        public string AddToDatabase(Stream stream, IList <string> addedXmls)
        {
            stream.Position = 0L;
            byte[] buffer   = new byte[1024];
            ushort groupLen = DatabaseStreamReader.ReadUShort(stream);

            stream.Read(buffer, 0, groupLen);
            string groupKey = Encoding.UTF8.GetString(buffer, 0, groupLen);

            if (mGroupXmls.ContainsKey(groupKey))
            {
                return(null);
            }
            ushort count = DatabaseStreamReader.ReadUShort(stream);

            string[]        xmls       = new string[count];
            GroupTypeFinder typeFinder = new GroupTypeFinder("Assembly-CSharp", groupKey);

            for (ushort i = 0; i < count; i++)
            {
                ushort nameLen = DatabaseStreamReader.ReadUShort(stream);
                //Debug.LogWarning(nameLen);
                stream.Read(buffer, 0, nameLen);
                string xmlName = Encoding.UTF8.GetString(buffer, 0, nameLen);
                int    offset  = DatabaseStreamReader.ReadInt(stream);
                if (mDataInfos.ContainsKey(xmlName))
                {
                    Debug.LogError(string.Format("Xml '{0}' is already existed !", xmlName));
                    continue;
                }
                mDataInfos.Add(xmlName, new DataInfo(stream, typeFinder, offset));
                xmls[i] = xmlName;
                if (addedXmls != null)
                {
                    addedXmls.Add(xmlName);
                }
            }
            ushort typeCount = DatabaseStreamReader.ReadUShort(stream);

            string[] typeNames = new string[typeCount];
            for (uint i = 0; i < typeCount; i++)
            {
                int len = stream.ReadByte();
                stream.Read(buffer, 0, len);
                typeNames[i] = Encoding.UTF8.GetString(buffer, 0, len);
            }
            typeFinder.SetTypes(typeNames);
            mGroupXmls.Add(groupKey, xmls);
            return(groupKey);
        }
        /// <summary>
        /// 将一个组中所有的xml数据加到数据库中,运行时将读取原始数据
        /// </summary>
        /// <param name="group">该组的所有信息</param>
        /// <param name="addedXmls">从组中加到数据库中的所有xml名称</param>
        /// <returns>组名称,若添加失败或该组已存在,则返回null</returns>
        public string AddToDatabase(XmlGroupSettings group, IList <string> addedXmls)
        {
            if (group == null)
            {
                return(null);
            }
            if (mGroupXmls.ContainsKey(group.group))
            {
                return(null);
            }
            GroupTypeFinder typeFinder = new GroupTypeFinder("Assembly-CSharp", group.group);
            List <string>   typeNames  = new List <string>();
            int             count      = group.xmlFiles.Length;

            string[] xmls = new string[count];
            for (int i = 0; i < count; i++)
            {
                XmlGroupSettings.XmlData data = group.xmlFiles[i];
                string xmlName = Path.GetFileNameWithoutExtension(data.path);
                if (mDataInfos.ContainsKey(xmlName))
                {
                    Debug.LogError(string.Format("Xml '{0}' is already existed !", xmlName));
                    continue;
                }
                int typeIndex = typeNames.IndexOf(data.typeName);
                if (typeIndex < 0)
                {
                    typeIndex = typeNames.Count;
                    typeNames.Add(data.typeName);
                }
                mDataInfos.Add(xmlName, new DataInfo(data.path, typeFinder, typeIndex));
                xmls[i] = xmlName;
                if (addedXmls != null)
                {
                    addedXmls.Add(xmlName);
                }
            }
            typeFinder.SetTypes(typeNames.ToArray());
            mGroupXmls.Add(group.group, xmls);
            return(group.group);
        }
        /// <summary>
        /// 将一个组中所有的sheet加到数据库中
        /// </summary>
        /// <param name="stream">该组的数据流</param>
        /// <param name="addedSheets">从组中加到数据库中的所有sheet名称</param>
        /// <returns>组名称,若添加失败或该组已存在,则返回null</returns>
        public string AddToDatabase(Stream stream, IList <string> addedSheets)
        {
            stream.Position = 0L;
            byte[] buffer      = new byte[1024];
            ushort groupKeyLen = DatabaseStreamReader.ReadUShort(stream);

            stream.Read(buffer, 0, groupKeyLen);
            string groupKey = Encoding.UTF8.GetString(buffer, 0, groupKeyLen);

            if (mGroupSheets.ContainsKey(groupKey))
            {
                return(null);
            }

            ushort sheetCount = DatabaseStreamReader.ReadUShort(stream);

            int[] sheetOffsets = new int[sheetCount];
            for (ushort i = 0; i < sheetCount; i++)
            {
                sheetOffsets[i] = DatabaseStreamReader.ReadInt(stream);
            }
            string[]        sheets     = new string[sheetCount];
            GroupTypeFinder typeFinder = new GroupTypeFinder("Assembly-CSharp", groupKey);

            for (ushort i = 0; i < sheetCount; i++)
            {
                stream.Position = sheetOffsets[i];
                ushort nameLen = DatabaseStreamReader.ReadUShort(stream);
                stream.Read(buffer, 0, nameLen);
                string sheetName = Encoding.UTF8.GetString(buffer, 0, nameLen);

                uint sheetItemCount = DatabaseStreamReader.ReadUInt(stream);
                //UnityEngine.Debug.LogError("sheet name : " + sheetName + "   item count : " + sheetItemCount);
                bool strKey = (sheetItemCount & 0x80000000) != 0u;
                sheetItemCount = sheetItemCount & 0x7fffffff;

                //UnityEngine.Debug.LogError("sheet item count : " + sheetItemCount);
                //UnityEngine.Debug.LogError("str key ? " + strKey);

                bool existed = mKeySheets.ContainsKey(sheetName) || mIdSheets.ContainsKey(sheetName);
                if (strKey)
                {
                    string[] keys    = new string[sheetItemCount];
                    int[]    offsets = new int[sheetItemCount];
                    for (int j = 0; j < sheetItemCount; j++)
                    {
                        int keyLen = stream.ReadByte();
                        //UnityEngine.Debug.Log(keyLen);
                        stream.Read(buffer, 0, keyLen);
                        keys[j]    = Encoding.UTF8.GetString(buffer, 0, keyLen);
                        offsets[j] = DatabaseStreamReader.ReadInt(stream);
                        //UnityEngine.Debug.LogWarning(string.Format("key : {0}    offset : {1}", keys[j], offsets[j]));
                    }
                    if (!existed)
                    {
                        KeySheetData sheet = new KeySheetData(stream, typeFinder, (int)sheetItemCount, keys, offsets);
                        mKeySheets.Add(sheetName, sheet);
                    }
                }
                else
                {
                    uint[] ids     = new uint[sheetItemCount];
                    int[]  offsets = new int[sheetItemCount];
                    for (int j = 0; j < sheetItemCount; j++)
                    {
                        ids[j]     = (uint)DatabaseStreamReader.ReadInt(stream);
                        offsets[j] = DatabaseStreamReader.ReadInt(stream);
                        //UnityEngine.Debug.LogWarning(string.Format("id : {0}    offset : {1}", ids[j], offsets[j]));
                    }
                    if (!existed)
                    {
                        IdSheetData sheet = new IdSheetData(stream, typeFinder, (int)sheetItemCount, ids, offsets);
                        mIdSheets.Add(sheetName, sheet);
                    }
                }
                if (existed)
                {
                    Debug.LogError(string.Format("Sheet '{0}' is already existed !", sheetName));
                }
                else
                {
                    sheets[i] = sheetName;
                    if (addedSheets != null)
                    {
                        addedSheets.Add(sheetName);
                    }
                    //Debug.Log("sheet : " + sheetName);
                }
            }
            ushort typeCount = DatabaseStreamReader.ReadUShort(stream);

            string[] typeNames = new string[typeCount];
            for (uint i = 0; i < typeCount; i++)
            {
                int len = stream.ReadByte();
                stream.Read(buffer, 0, len);
                typeNames[i] = Encoding.UTF8.GetString(buffer, 0, len);
            }
            typeFinder.SetTypes(typeNames);
            mGroupSheets.Add(groupKey, sheets);
            return(groupKey);
        }