Beispiel #1
0
        /// <summary>
        /// 从指定目录异步加载资源
        /// </summary>
        /// <param name="directory">目录,必须带header,因为要使用www加载</param>
        /// <returns></returns>
        IEnumerator LoadAsync(string directory, string pkgPath, Action <ResObj> complete, Action <float> progress = null)
        {
            UnityWebRequest www = new UnityWebRequest(FileUtil.CombinePaths(directory, pkgPath, OriginPath));

            yield return(www.SendWebRequest());

            while (!www.isDone)
            {
                if (progress != null)
                {
                    progress(www.downloadProgress);
                }

                yield return(null);
            }

            if (www != null && www.isDone && !string.IsNullOrEmpty(www.error))
            {
                OnBinaryLoaded(www.downloadHandler.data);
            }

            if (complete != null)
            {
                complete(this);
            }
            if (www != null)
            {
                www.Dispose();
                www = null;
            }
        }
Beispiel #2
0
        //异步获取
        public IEnumerator LoadAsync(Action <ResObj> complete = null, Action <float> progress = null)
        {
#if UNITY_EDITOR
            if (!string.IsNullOrEmpty(Ext))
            {
                string pp = FileUtil.CombinePaths("file:///", Application.dataPath);
                yield return(LoadAsync(pp, "", complete, progress));
            }
            else
#endif
            {
                ResourceRequest request = ExtResources.LoadAsync(Path);
                yield return(request);

                if (request != null)
                {
                    _content = request.asset;
                    PostProcessContent();
                }

                if (complete != null)
                {
                    complete(this);
                }
            }
        }