コード例 #1
0
            /// <summary>
            /// 以字节流的形式载入资源
            /// </summary>
            private IEnumerator LoadBundleAsync(string bundleName, string bundleVersion, BundleLoadMethod method,
                                                bool saveBundle = false)
            {
                string bundlePath;
                var    container = new BundleContainer();

                switch (method)
                {
                case BundleLoadMethod.File_StreamingBundle:
                    bundlePath = @Path.Combine(Application.streamingAssetsPath, bundleName);
                    break;

                case BundleLoadMethod.File_LocalBundle:
                    bundlePath = pather.GetLocalBundlePath(bundleName, bundleVersion);
                    break;

                default:
                    bundlePath = pather.GetServeBundlePath(bundleName, bundleVersion);
                    break;
                }

                yield return(ExecuteLoadBundleAsync(bundlePath, method, container));

                onLoadEveryComplete(container.assetBundle);

                if (saveBundle && container.bytes != null)
                {
                    var filePath = pather.GetLocalBundlePath(bundleName, bundleVersion);
                    FileUtil.CreateFile(filePath, container.bytes);
                }
            }
コード例 #2
0
            /// <summary>
            /// 从服务器下载并保存新资源包
            /// </summary>
            /// <param name="bundleName"></param>
            /// <param name="bundleVersion"></param>
            /// <returns></returns>
            private IEnumerator DownloadAndSaveBundle(string bundleName, string bundleVersion)
            {
                //获取服务器请求url
                var requestUrl          = pather.GetServeBundlePath(bundleName, bundleVersion);
                var webBytesLoadRequest = UnityWebRequest.Get(requestUrl);

                yield return(webBytesLoadRequest.SendWebRequest());

                byte[] bs = webBytesLoadRequest.downloadHandler.data;
                //获取本地包存储路径
                var localPath = pather.GetLocalBundlePath(bundleName, bundleVersion);

                //将服务器获得的新包数据保存到本地
                FileUtil.CreateFile(localPath, bs);
            }