示例#1
0
    public static IEnumerator LoadConfigData()
    {
//        Debug.Log("表的路径是: " + AssetBundlePath.GetStreamingAssetsPath());

        string path = AssetBundlePath.GetStreamingAssetsPath();

        string[] fileNames = PlayerPrefs.GetString(StaticTag.PLAYERPREFS_CONFIG).Split('|');

        int   count     = fileNames.Length;
        float startTime = Time.realtimeSinceStartup;

        for (int i = 0; i < count; ++i)
        {
            WWW www = new WWW(path + fileNames[i]);
            yield return(www);

            ParseFile(www.bytes, www.url);
            Debug.LogFormat("###Load {0} Success!###", fileNames[i]);
        }
        Debug.LogFormat("load all data time: {0}", (Time.realtimeSinceStartup - startTime));

        allConfigLoaded = true;
    }
示例#2
0
        private static void ExportBin(string filePath, string filename)
        {
            ByteArray ba = new ByteArray();

            Assembly asm = Assembly.LoadFile(Application.dataPath + "/../Library/ScriptAssemblies/Assembly-CSharp.dll");

            DataSet dataSet = DataSetHelper.CreateDataSet(filePath + filename + FILE_SUFFIX);

            if (dataSet != null)
            {
                //int sheetNum = dataSet.Tables.Count;

                int canreadSheet = 0;
                foreach (DataTable sheet in dataSet.Tables)
                {
                    string className = sheet.TableName;
                    object obj       = asm.CreateInstance(className);

                    //Debug.Log("当前表名是: " + sheet.TableName);
                    if (obj == null)
                    {
                        continue;
                    }
                    ++canreadSheet;
                }
                ba.writeInt(canreadSheet);
                //Converter.WriteInt(writer, sheetNum);
                foreach (DataTable sheet in dataSet.Tables)
                {
                    string className = sheet.TableName;
                    object obj       = asm.CreateInstance(className);
                    if (obj == null)
                    {
                        //MUtils.ShowNotice("Load data error: "+className+" in "+filePath+" has no data.");
                        continue;
                    }
                    FieldInfo[] fis = obj.GetType().GetFields();

                    ba.writeUTF(sheet.TableName);
                    //Converter.WriteJavaString(writer,sheet.TableName);

                    int rows     = sheet.Rows.Count;
                    int rowCount = 0;
                    for (int r = 0; r != rows; ++r)
                    {
                        if (string.IsNullOrEmpty(sheet.Rows[r].ItemArray[0].ToString()))
                        {
                            break;
                        }

                        rowCount++;
                    }
                    ba.writeInt(rowCount);
                    if (rows > 0)
                    {
                        ba.writeInt(sheet.Rows[0].ItemArray.Length);
                    }
                    else
                    {
                        ba.writeInt(0);
                    }

                    foreach (DataRow row in sheet.Rows)
                    {
                        int i = 0;
                        foreach (object item in row.ItemArray)
                        {
                            if (i >= fis.Length)
                            {
                                break;
                            }

                            if (fis[i].FieldType == typeof(int))
                            {
                                int val = 0;
                                int.TryParse(item.ToString(), out val);
                                ba.writeInt(val);
                            }
                            else if (fis[i].FieldType == typeof(short))
                            {
                                short val = 0;
                                short.TryParse(item.ToString(), out val);
                                ba.writeShort(val);
                            }
                            else if (fis[i].FieldType == typeof(long))
                            {
                                long val = 0;
                                long.TryParse(item.ToString(), out val);
                                ba.writeLong(val);
                            }
                            else if (fis[i].FieldType == typeof(float) || fis[i].FieldType == typeof(double) ||
                                     fis[i].FieldType == typeof(string))
                            {
                                ba.writeUTF(item.ToString());
                            }

                            ++i;
                        }
                    }
                }
            }

            //string binpath = AssetBundlePath.GetStreamingAssetsPath() + "bin/".Replace("file://","");
            string binpath = AssetBundlePath.GetStreamingAssetsPath().Replace("file://", "");

            binpath = binpath.Replace("file://", "");

            var file = new FileStream(binpath + filename + FILE_BIN_SUFFIX, FileMode.Create, System.IO.FileAccess.Write);

            byte[] bytes = ba.data;
            file.Write(bytes, 0, bytes.Length);
            file.Close();
        }