Пример #1
0
        // 开始一个下载任务
        private void StartTask(DownloadInfo taskinfo)
        {
            if (this.m_DownloadingTasks.ContainsKey(taskinfo.fileName))
            {
                Debug.LogErrorFormat("task already in progress :{0}", taskinfo.fileName);
            }
            else
            {
                DownloadingTask value = new DownloadingTask(taskinfo);
                this.m_DownloadingTasks[taskinfo.fileName] = value;

                if (!File.Exists(taskinfo.tempPath))
                {
                    FilePathTools.CreateFolderByFilePath(taskinfo.tempPath);
                    File.Create(taskinfo.tempPath).Dispose();
                }

                using (var sw = new FileStream(taskinfo.tempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    taskinfo.downloadedSize = (int)sw.Length;
                }

                HttpDownload(value);
            }
        }
Пример #2
0
        // 添加一个下载任务
        public DownloadInfo DownloadInSeconds(string filename, string md5, Action <DownloadInfo> onComplete)
        {
            filename = FilePathTools.NormalizePath(filename);
            DownloadInfo info = new DownloadInfo(filename, md5, onComplete);

            pendingDownloads.Enqueue(info);
            return(info);
        }
Пример #3
0
        /// <summary>
        /// 获取资源的相对路径,在Export基础上
        /// </summary>
        /// <returns></returns>
        public static string GetShortPathRelativeExport(string fullpath)
        {
            fullpath = FilePathTools.NormalizePath(fullpath);
            int    i  = fullpath.IndexOf("Export/");
            string sp = fullpath.Substring(i + 7);

            return(sp);
        }
Пример #4
0
 public AssetBundleInfo GuessBundleByAssetName(string assetName)
 {
     return(_versionInfo.GuessBundleByAssetName(FilePathTools.NormalizePath(assetName.ToLower())));
 }
Пример #5
0
        /// <summary>
        /// 打Group的Bundle,并生成Group的version信息
        /// </summary>
        /// <param name="singleGroup"></param>
        public static void BuildGroup(BundleGroup singleGroup, string exportPath, BuildTarget buildTarget = BuildTarget.NoTarget)
        {
            List <string> paths = singleGroup.GetBundlePaths(GetBundleMethod.All);

            if (paths == null || paths.Count <= 0)
            {
                return;
            }

            string groupName = singleGroup.GroupName;

            if (!Directory.Exists(exportPath))
            {
                Directory.CreateDirectory(exportPath);
            }

            List <AssetBundleBuild> buildMap = new List <AssetBundleBuild>();

            //打AssetBundle包
            for (int i = 0; i < paths.Count; i++)
            {
                string           fullPath   = string.Format("{0}/{1}/{2}", Application.dataPath, "Export", paths[i]);
                AssetBundleBuild build      = new AssetBundleBuild();
                List <string>    assetnames = new List <string>();
                if (File.Exists(fullPath))
                {
                    string itemPath = paths[i];
                    int    lastDot  = itemPath.LastIndexOf(".");
                    if (lastDot > 0)
                    {
                        build.assetBundleName = itemPath.Substring(0, lastDot);
                    }
                    else
                    {
                        build.assetBundleName = itemPath;
                    }
                    assetnames.Add(FilePathTools.GetRelativePath(fullPath));
                }
                else
                {
                    build.assetBundleName = paths[i];
                    FileInfo[] files = FileUtil.GetFiles(fullPath);
                    if (files.Length <= 0)
                    {
                        continue;
                    }

                    for (int j = 0; j < files.Length; j++)
                    {
                        //Debug.Log(files[j]);
                        string path = FilePathTools.GetRelativePath(files[j].FullName);
                        if (path.Contains(".DS_Store") || path.Contains(".gitkeep"))
                        {
                            continue;
                        }
                        assetnames.Add(path);
                    }
                }

                foreach (string assetName in assetnames)
                {
                    AssetImporter.GetAtPath(assetName).SetAssetBundleNameAndVariant(build.assetBundleName, string.Empty);
                }

                build.assetNames = assetnames.ToArray();
                buildMap.Add(build);
            }
            AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(
                exportPath,
                buildMap.ToArray(),
                BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.DeterministicAssetBundle,
                buildTarget == BuildTarget.NoTarget ? EditorUserBuildSettings.activeBuildTarget : buildTarget
                );



            //生成Version Item Info
            AssetBundleGroupInfo assetBundleGroupInfo = new AssetBundleGroupInfo(singleGroup.GroupName, singleGroup.BaseGroup);

            string[] builtAssetBundleNames = assetBundleManifest.GetAllAssetBundles();
            for (var i = 0; i < builtAssetBundleNames.Length; ++i)
            {
                string     assetBundlePath = string.Format("{0}/{1}", exportPath, builtAssetBundleNames[i]);
                string     path            = Directory.GetCurrentDirectory();
                BundleInfo bundleInfo      = singleGroup.GetBundleInfo(builtAssetBundleNames[i]);

                string          md5  = AssetUtils.BuildFileMd5(assetBundlePath);
                int             size = AssetUtils.FileSize(assetBundlePath);
                AssetBundleInfo localAssetBundleInfo = new AssetBundleInfo
                {
                    AssetBundleName         = builtAssetBundleNames[i],
                    DependenciesBundleNames = assetBundleManifest.GetAllDependencies(builtAssetBundleNames[i]),
                    releaseMode             = bundleInfo.releaseMode,
                    BaseBundle = bundleInfo.BaseBundle
                };
                localAssetBundleInfo.HashString = md5;  // 初始包里的ab包,原样拷贝md5
                localAssetBundleInfo.Size       = size; // bundle的尺寸
                assetBundleGroupInfo.Add(localAssetBundleInfo.AssetBundleName, localAssetBundleInfo);
            }
            assetBundleVersionInfo.Add(groupName, assetBundleGroupInfo);
        }
        /// <summary>
        /// 从编辑器里加载资源
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <returns></returns>
        private T LoadEditorResource <T>(string name) where T : UObject
        {
            List <string> path = new List <string>();

            if (typeof(T) == typeof(Sprite))
            {
                path.Add(name + ".png");
                path.Add(name + ".jpg");
            }
            else if (typeof(T) == typeof(Texture2D))
            {
                path.Add(name + ".png");
                path.Add(name + ".jpg");
            }
            else if (typeof(T) == typeof(GameObject))
            {
                path.Add(name + ".prefab");
            }
            else if (typeof(T) == typeof(AudioClip))
            {
                path.Add(name + ".mp3");
                path.Add(name + ".wav");
                path.Add(name + ".ogg");
            }
            else if (typeof(T) == typeof(Material))
            {
                path.Add(name + ".mat");
            }
            else if (typeof(T) == typeof(TextAsset))
            {
                path.Add(name + ".txt");
                path.Add(name + ".json");
                path.Add(name + ".xml");
            }
            else if (typeof(T) == typeof(SpriteAtlas))
            {
                path.Add(name + ".spriteatlas");
            }
            //else if (typeof(T) == typeof(TMPro.TMP_FontAsset))
            //{
            //    path.Add(name + ".asset");
            //}
            else if (typeof(T) == typeof(Material))
            {
                path.Add(name + ".mat");
            }
            else if (typeof(T) == typeof(SkeletonDataAsset))
            {
                path.Add(name + ".asset");
            }



            foreach (string itempath in path)
            {
                string normalizepath = FilePathTools.NormalizePath(itempath);
#if UNITY_EDITOR
                string  _editorPath = FilePathTools.GetAssetEditorPath(normalizepath);
                UObject Obj         = UnityEditor.AssetDatabase.LoadAssetAtPath(_editorPath, typeof(T));

                if (Obj != null)
                {
                    return((T)Obj);
                }
#endif
            }
            return(null);
        }