Load www, A wrapper of WWW.
Inheritance: AbstractResourceLoader
Beispiel #1
0
        private IEnumerator CoLoad(string url)
        {
            var getResPathType = KResourceModule.GetResourceFullPath(url, _loaderMode == LoaderMode.Async, out _fullUrl);

            if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid)
            {
                if (Debug.isDebugBuild)
                {
                    Log.Error("[HotBytesLoader]Error Path: {0}", url);
                }
                OnFinish(null);
                yield break;
            }

            if (_loaderMode == LoaderMode.Sync)
            {
                // 存在应用内的,StreamingAssets内的,同步读取;否则去PersitentDataPath
                if (getResPathType == KResourceModule.GetResourceFullPathType.InApp)
                {
                    if (Application.isEditor) // Editor mode : 读取Product配置目录
                    {
                        var loadSyncPath = Path.Combine(KResourceModule.ProductPathWithoutFileProtocol, url);
                        Bytes = KResourceModule.ReadAllBytes(loadSyncPath);
                    }
                    else // product mode: read streamingAssetsPath
                    {
                        Bytes = KResourceModule.LoadSyncFromStreamingAssets(url);
                    }
                }
                else
                {
                    Bytes = KResourceModule.ReadAllBytes(_fullUrl);
                }
            }
            else
            {
                _wwwLoader = KWWWLoader.Load(_fullUrl);
                while (!_wwwLoader.IsCompleted)
                {
                    Progress = _wwwLoader.Progress;
                    yield return(null);
                }

                if (!_wwwLoader.IsSuccess)
                {
                    //if (AssetBundlerLoaderErrorEvent != null)
                    //{
                    //    AssetBundlerLoaderErrorEvent(this);
                    //}
                    Log.Error("[HotBytesLoader]Error Load WWW: {0}", url);
                    OnFinish(null);
                    yield break;
                }

                Bytes = _wwwLoader.Www.bytes;
            }

            OnFinish(Bytes);
        }
 protected override void OnFinish(object resultObj)
 {
     if (_wwwLoader != null)
     {
         // 释放WWW加载的字节。。释放该部分内存,因为AssetBundle已经自己有缓存了
         _wwwLoader.Release();
         _wwwLoader = null;
     }
     base.OnFinish(resultObj);
 }
Beispiel #3
0
        private IEnumerator CoLoad(string url)
        {
            if (_loaderMode == LoaderMode.Sync)
            {
                Bytes = KResourceModule.LoadAssetsSync(url);
            }
            else
            {
                string _fullUrl;
                var    getResPathType = KResourceModule.GetResourceFullPath(url, _loaderMode == LoaderMode.Async, out _fullUrl);
                if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid)
                {
                    Log.Error("[HotBytesLoader]Error Path: {0}", url);
                    OnFinish(null);
                    yield break;
                }

                _wwwLoader = KWWWLoader.Load(_fullUrl);
                while (!_wwwLoader.IsCompleted)
                {
                    Progress = _wwwLoader.Progress;
                    yield return(null);
                }

                if (!_wwwLoader.IsSuccess)
                {
                    //if (AssetBundlerLoaderErrorEvent != null)
                    //{
                    //    AssetBundlerLoaderErrorEvent(this);
                    //}
                    Log.Error("[HotBytesLoader]Error Load WWW: {0}", url);
                    OnFinish(null);
                    yield break;
                }
#if UNITY_2018_1_OR_NEWER //TODO 换成WebRequst
                //Bytes = _wwwLoader.Www.downloadHandler.data;
                Bytes = _wwwLoader.Www.bytes;
#else
                Bytes = _wwwLoader.Www.bytes;
#endif
            }

            OnFinish(Bytes);
        }
Beispiel #4
0
        private IEnumerator CoLoad(string url)
        {
            if (_loaderMode == LoaderMode.Sync)
            {
                Bytes = LoadSync(url);
            }
            else
            {
                var getResPathType = KResourceModule.GetResourceFullPath(url, _loaderMode == LoaderMode.Async, out _fullUrl);
                if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid)
                {
                    if (Debug.isDebugBuild)
                    {
                        Log.Error("[HotBytesLoader]Error Path: {0}", url);
                    }
                    OnFinish(null);
                    yield break;
                }

                _wwwLoader = KWWWLoader.Load(_fullUrl);
                while (!_wwwLoader.IsCompleted)
                {
                    Progress = _wwwLoader.Progress;
                    yield return(null);
                }

                if (!_wwwLoader.IsSuccess)
                {
                    //if (AssetBundlerLoaderErrorEvent != null)
                    //{
                    //    AssetBundlerLoaderErrorEvent(this);
                    //}
                    Log.Error("[HotBytesLoader]Error Load WWW: {0}", url);
                    OnFinish(null);
                    yield break;
                }

                Bytes = _wwwLoader.Www.bytes;
            }

            OnFinish(Bytes);
        }
Beispiel #5
0
 protected override void OnFinish(object resultObj)
 {
     if (_wwwLoader != null)
     {
         // 释放WWW加载的字节。。释放该部分内存,因为AssetBundle已经自己有缓存了
         _wwwLoader.Release();
         _wwwLoader = null;
     }
     base.OnFinish(resultObj);
 }
Beispiel #6
0
        private IEnumerator CoLoad(string url)
        {
            var getResPathType = KResourceModule.GetResourceFullPath(url, _loaderMode == LoaderMode.Async, out _fullUrl);
            if (getResPathType == KResourceModule.GetResourceFullPathType.Invalid)
            {
                if (Debug.isDebugBuild)
                    Log.Error("[HotBytesLoader]Error Path: {0}", url);
                OnFinish(null);
                yield break;
            }

            if (_loaderMode == LoaderMode.Sync)
            {
                // 存在应用内的,StreamingAssets内的,同步读取;否则去PersitentDataPath
                if (getResPathType == KResourceModule.GetResourceFullPathType.InApp)
                {
                    if (Application.isEditor) // Editor mode : 读取Product配置目录
                    {
                        var loadSyncPath = Path.Combine(KResourceModule.BundlesPathWithoutFileProtocol, url);
                        Bytes = File.ReadAllBytes(loadSyncPath);
                    }
                    else // product mode: read streamingAssetsPath
                    {
                        Bytes = KResourceModule.LoadSyncFromStreamingAssets(KResourceModule.BundlesPathRelative + url);
                    }
                }
                else
                {
                    Bytes = File.ReadAllBytes(_fullUrl);
                }
            }
            else
            {

                _wwwLoader = KWWWLoader.Load(_fullUrl);
                while (!_wwwLoader.IsCompleted)
                {
                    Progress = _wwwLoader.Progress;
                    yield return null;
                }

                if (!_wwwLoader.IsSuccess)
                {
                    //if (AssetBundlerLoaderErrorEvent != null)
                    //{
                    //    AssetBundlerLoaderErrorEvent(this);
                    //}
                    Log.Error("[HotBytesLoader]Error Load WWW: {0}", url);
                    OnFinish(null);
                    yield break;
                }

                Bytes = _wwwLoader.Www.bytes;

            }

            OnFinish(Bytes);
        }