public DownloadInfo DownloadInSeconds(string directoryName, string filename, string md5, Action <DownloadInfo> onComplete, Action <int, int> onProgressChange = null)
        {
            filename = FilePathTools.NormalizePath(filename);
            DownloadInfo info = new DownloadInfo(directoryName, filename, md5, onComplete, onProgressChange);

            pendingDownloads.Enqueue(info);
            return(info);
        }
        // 下载运营活动/礼包的资源
        public DownloadInfo DownloadInSeconds(string directoryName, string fileNameWithMd5, ActivityResType resType, Action <DownloadInfo> onComplete)
        {
            fileNameWithMd5 = FilePathTools.NormalizePath(fileNameWithMd5);
            DownloadInfo info = new DownloadInfo(directoryName, fileNameWithMd5, resType, onComplete);

            pendingDownloads.Enqueue(info);
            return(info);
        }
        // 添加一个下载任务
        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);
        }
예제 #4
0
        public AssetBundleAsyncLoader LoadAssetBundleAsync(string path, AssetBundleAsyncLoader.LoaderCompleteHandler handler = null)
        {
            string normalizepath          = FilePathTools.NormalizePath(path.ToLower());
            AssetBundleAsyncLoader loader = this.CreateLoader(normalizepath);

            loader.onComplete += handler;
            if (!_isCurrentLoading)
            {
                _isCurrentLoading = true;
                //Application.backgroundLoadingPriority = ThreadPriority.High;
            }
            _nonCompleteLoaderSet.Add(loader);
            return(loader);
        }
예제 #5
0
        public void ReleaseRes(string path, bool free = false)
        {
            var norm_path = FilePathTools.NormalizePath(path);

            if (dicCacheObject.TryGetValue(norm_path, out CacheObject oc))
            {
                dicCacheObject.Remove(norm_path);
                if (free)
                {
                    if (oc.obj is Sprite)
                    {
                        var sp = oc.obj as Sprite;
                        Resources.UnloadAsset(sp.texture);
                    }
                    else
                    {
                        Resources.UnloadAsset(oc.obj);
                    }
                }
            }
            string bundlePath = Path.GetDirectoryName(path) + ".ab";

            AssetBundleCache.Unload(bundlePath);
        }
예제 #6
0
        public void LoadResourceAsync <T>(string name, Action <T> OnFinished = null) where T : Object
        {
            List <string> path = new List <string>();

            if (AssetConfigController.Instance.UseAssetBundle)
            {
                string      normalizepath = FilePathTools.NormalizePath(name.ToLower());
                CacheObject co;
                if (dicCacheObject.TryGetValue(normalizepath, out co) && co.obj != null)
                {
                    OnFinished?.Invoke(co.obj as T);
                }
                else
                {
                    if (!alwaysCache)
                    {
                        TryClearCache();
                    }

                    string bundlePath = Path.GetDirectoryName(normalizepath) + ".ab";
                    string assetName  = Path.GetFileName(normalizepath);

                    AssetBundle targetAb;
                    targetAb = AssetBundleCache.GetAssetBundle(bundlePath);
                    if (targetAb != null)
                    {
                        StartCoroutine(LoadFromAssetBundle <T>(targetAb, assetName, (obj) =>
                        {
                            AddCache(normalizepath, obj);
                            OnFinished?.Invoke(obj);
                        }));
                    }
                    else
                    {
                        LoadAssetBundleAsync(bundlePath, (loader) =>
                        {
                            if (loader.IsComplete)
                            {
                                StartCoroutine(LoadFromAssetBundle <T>(loader.AssetBundle, assetName, (obj) =>
                                {
                                    AddCache(normalizepath, obj);
                                    OnFinished?.Invoke(obj);
                                }));
                            }
                        });
                    }
                }
            }
            else
            {
                if (typeof(T) == typeof(Sprite))
                {
                    path.Add(name + ".png");
                    path.Add(name + ".jpg");
                    path.Add(name + ".tga");
                }
                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");
                }
                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");
                    path.Add(name + ".bytes");
                }
                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(RuntimeAnimatorController))
                {
                    path.Add(name + ".controller");
                }

                foreach (string itempath in path)
                {
                    string normalizepath = FilePathTools.NormalizePath(itempath);
                    object obj           = SubLoadResource <T>(normalizepath);
                    if (obj != null)
                    {
                        OnFinished?.Invoke(obj as T);
                        break;
                    }
                }
            }
        }
예제 #7
0
        public T LoadResource <T>(string name, bool forceBundle = false, bool addToCache = true) where T : Object
        {
#if DEVELOPMENT_BUILD || UNITY_EDITOR
            stopWatch.Restart();
#endif
            try
            {
                List <string> path = new List <string>();
                if (AssetConfigController.Instance.UseAssetBundle || forceBundle)
                {
                    string      normalizepath = FilePathTools.NormalizePath(name.ToLower());
                    CacheObject co;
                    T           outValue;
                    if (dicCacheObject.TryGetValue(normalizepath, out co) && co != null && co.obj != null &&
                        TryGetCoValue <T>(co, out outValue) && outValue != null)
                    {
                        return(outValue);
                    }
                    else
                    {
                        if (!alwaysCache)
                        {
                            TryClearCache();
                        }
                        object obj = SubLoadResource <T>(normalizepath, forceBundle, addToCache);
                        if (obj != null)
                        {
                            return(obj as T);
                        }
                    }
                }
                else
                {
                    if (typeof(T) == typeof(Sprite))
                    {
                        path.Add(name + ".png");
                        path.Add(name + ".jpg");
                        path.Add(name + ".tga");
                    }
                    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");
                    }
                    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");
                        path.Add(name + ".bytes");
                    }
                    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(RuntimeAnimatorController))
                    {
                        path.Add(name + ".controller");
                    }
#if CK_CLIENT
                    else if (typeof(T) == typeof(Spine.Unity.SkeletonDataAsset))
                    {
                        path.Add(name + ".asset");
                    }
#endif

                    foreach (string itempath in path)
                    {
                        string normalizepath = FilePathTools.NormalizePath(itempath);
                        object obj           = SubLoadResource <T>(normalizepath, false, addToCache);
                        if (obj != null)
                        {
                            return(obj as T);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DebugUtil.LogError(e);
            }
#if DEVELOPMENT_BUILD || UNITY_EDITOR
            finally
            {
                stopWatch.Stop();
                long time_delta = stopWatch.ElapsedMilliseconds;
                loadTimes += time_delta;

                loadTimeMarks.Add(new LoadTimeMark(name, time_delta));
            }
#endif

            return(null);
        }