예제 #1
0
        public static AssetBundleInfoList Deserialize(string txt)
        {
            AssetBundleInfoList list = new AssetBundleInfoList();

            using (StringReader stringReader = new StringReader(txt))
            {
                while (stringReader.Peek() >= 0)
                {
                    string line = stringReader.ReadLine();
                    if (!string.IsNullOrEmpty(line))
                    {
                        string[]        seg  = line.Split(';');
                        AssetBundleInfo item = new AssetBundleInfo();
                        item.path            = seg[0];
                        item.assetBundleName = seg[1];
                        item.assetName       = seg[2];
                        item.objType         = seg[3];
                        list.Add(item);
                    }
                }
            }

            return(list);
        }
        //path;md5;objType;assetName;assetBundleName;manifestName
        public static void Generator(bool developMode = false)
        {
            List <string> fileList = new List <string>();

            string platformRoot = AssetManagerSetting.EditorRootPlatform;

            string filecsv = AssetManagerSetting.EditorFileCsvForStreaming;

            if (File.Exists(filecsv))
            {
                File.Delete(filecsv);
            }
            PathUtil.CheckPath(filecsv);


            FileStream   fs = new FileStream(filecsv, FileMode.CreateNew);
            StreamWriter sw = new StreamWriter(fs);

            string fileinfo;
            string path, md5, objType, assetName, assetBundleName;
            string file;


            AssetBundleInfoList infoList = AssetBundleEditor.GeneratorAssetBundleInfo();

            if (developMode)
            {
                for (int i = 0; i < infoList.list.Count; i++)
                {
                    AssetBundleInfo item = infoList.list[i];
                    fileinfo = SerializeFile("{0}/" + item.assetBundleName, "", item.objType, item.assetBundleName, item.assetName);
                    sw.WriteLine(fileinfo);
                }
            }
            else
            {
                // streamingAssetsPath下非platform
                fileList.Clear();
                if (Directory.Exists(Application.streamingAssetsPath))
                {
                    PathUtil.RecursiveFileFilter(Application.streamingAssetsPath, fileList, new List <string>(new string[] { ".meta" }), new List <string>(new string[] { "platform", "users" }));

                    for (int i = 0; i < fileList.Count; i++)
                    {
                        file = fileList[i];
                        if (file.IndexOf("test_") != -1 ||
                            file.IndexOf("crash_report") != -1 ||
                            file.IndexOf("AssetBundleList.csv") != -1 ||
                            file.IndexOf("AssetList.csv") != -1 ||
                            file.IndexOf("version_") != -1
                            )
                        {
                            continue;
                        }



                        path     = file.Replace(Application.streamingAssetsPath + "/", string.Empty);
                        md5      = PathUtil.md5file(file);
                        fileinfo = SerializeFile(path, md5);
                        sw.WriteLine(fileinfo);
                    }
                }

                // config.assetbunld, luacode.assetbunld
                List <string> cl = new List <string>();

                string[] byteFiles = new string[] { "config", "luacode" };
                for (int i = 0; i < byteFiles.Length; i++)
                {
                    file = platformRoot + "/" + byteFiles[i] + AssetManagerSetting.AssetbundleExt;
                    if (!File.Exists(file))
                    {
                        continue;
                    }

                    cl.Add(file);
                    path     = file.Replace(platformRoot, "{0}");
                    md5      = PathUtil.md5file(file);
                    fileinfo = SerializeFile(path, md5);
                    sw.WriteLine(fileinfo);
                }


                // streamingAssetsPath下platform
                fileList.Clear();
                Recursive(platformRoot, fileList);



                objType = "";
                int count = fileList.Count;
                for (int i = 0; i < count; i++)
                {
                    if (i % 20 == 0)
                    {
                        EditorUtility.DisplayProgressBar("生成文件MD5", i + "/" + count, 1f * i / count);
                    }
                    file            = fileList[i];
                    path            = file.Replace(platformRoot, "{0}");
                    assetBundleName = file.Replace(platformRoot + "/", string.Empty);
                    md5             = PathUtil.md5file(file);

                    if (infoList.Has(assetBundleName))
                    {
                        AssetBundleInfo info = infoList.Get(assetBundleName);
                        assetName = info.assetName;
                        objType   = info.objType;
                    }
                    else
                    {
                        assetName = Path.GetFileName(file);
                        if (path.IndexOf("{0}/assets") == 0)
                        {
                            assetName = "";
                        }
                        else if (path == "{0}/" + Platform.PlatformDirectoryName)
                        {
                            assetName = "assetbundlemanifest";
                        }
                        else
                        {
                            assetName = assetName.Replace(AssetManagerSetting.AssetbundleExt, string.Empty);
                            assetName = PathUtil.ChangeExtension(assetName, string.Empty);
                        }
                    }


                    fileinfo = SerializeFile(path, md5, objType, assetBundleName, assetName);
                    sw.WriteLine(fileinfo);
                }
            }



            fileinfo = SerializeFile("{0}/" + AssetManagerSetting.FilesName, DateTime.Now.ToString("yyyyMMddHHmmss"));
            sw.WriteLine(fileinfo);


            sw.Close(); fs.Close();
            AssetDatabase.Refresh();
            Debug.Log("[FilesGenerator]" + filecsv);

            EditorUtility.ClearProgressBar();
        }