Exemple #1
0
        public static async Task <LoaderRequest> Load(string rURL)
        {
            LoaderRequest rRequest    = new LoaderRequest(rURL);
            string        rVersionURL = rRequest.Url;

            WWWAssist.LoaderRequest rWWWVersionRequest = await WWWAssist.LoadFile(rVersionURL);

            if (rWWWVersionRequest.Bytes == null || rWWWVersionRequest.Bytes.Length == 0)
            {
                return(null);
            }

            ABVersion rVersion = new ABVersion();

            using (var ms = new MemoryStream(rWWWVersionRequest.Bytes))
            {
                using (var br = new BinaryReader(ms))
                {
                    rVersion.Deserialize(br);
                }
            }
            rRequest.Version = rVersion;

            return(rRequest);
        }
Exemple #2
0
        public IEnumerator Initialize()
        {
            GameLoading.Instance.StartLoading(1.0f, "游戏初始化阶段,开始检查资源更新...");

            // 加载Streaming空间下的版本MD5码
            var rStreamingMD5Request = WWWAssist.LoadFile(ABPlatform.Instance.GetStreamingUrl_CurPlatform(ABVersion.ABVersion_File_MD5));

            yield return(rStreamingMD5Request);

            mStreamingMD5 = rStreamingMD5Request.Text;
            Debug.Log("--- Streaming MD5: " + mStreamingMD5);

            if (!ABPlatform.Instance.IsDevelopeMode())
            {
                // 加载Persitent空间下的版本MD5码
                var rPersistentMD5Request = WWWAssist.LoadFile(ABPlatform.Instance.GetPersistentUrl_CurPlatform(ABVersion.ABVersion_File_MD5));
                yield return(rPersistentMD5Request);

                mPersistentMD5 = rPersistentMD5Request.Text;
                Debug.Log("--- Persistent MD5: " + mPersistentMD5);

                // 加载服务器上的版本MD5码
                var rServerMD5Request = WebRequestAssist.DownloadFile(ABPlatform.Instance.GetServerUrl_CurPlatform(ABVersion.ABVersion_File_MD5));
                yield return(rServerMD5Request);

                mServerMD5 = rServerMD5Request.Text;
                Debug.Log("--- Server MD5: " + mServerMD5);

                // 加载Persisntent空间的版本信息文件
                var rPersistentVersionRequest = ABVersion.Load(ABPlatform.Instance.GetPersistentUrl_CurPlatform(ABVersion.ABVersion_File_Bin));
                yield return(rPersistentVersionRequest);

                mPersistentVersion = rPersistentVersionRequest.Version;

                if (!string.IsNullOrEmpty(mServerMD5) && !mServerMD5.Equals(mPersistentMD5))
                {
                    GameLoading.Instance.Hide();

                    // 开始下载
                    yield return(this.UpdateResource_Sync());
                }
            }

            GameLoading.Instance.StartLoading(0.2f, "游戏初始化阶段,开始加载资源...");

            // 加载Streaming空间的版本信息文件
            var rStreamingVersionRequest = ABVersion.Load(ABPlatform.Instance.GetStreamingUrl_CurPlatform(ABVersion.ABVersion_File_Bin));

            yield return(rStreamingVersionRequest);

            mStreamingVersion = rStreamingVersionRequest.Version;

            // 生成最终用于资源加载的版本信息
            this.GenerateCombineVersion();

            GameLoading.Instance.Hide();
        }
Exemple #3
0
        /// <summary>
        /// 加载Manifest
        /// </summary>
        private static IEnumerator LoadManifest(string rManifestURL, Action <AssetBundleManifest> rLoadCompleted)
        {
            WWW www = new WWW(rManifestURL);

            yield return(www);

            if (www == null || !string.IsNullOrEmpty(www.error))
            {
                Debug.Log("加载Manifest出错: " + www.error);
                UtilTool.SafeExecute(rLoadCompleted, null);
                yield break;
            }
            var rABManifest = www.assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest") as AssetBundleManifest;

            WWWAssist.Dispose(ref www);
            UtilTool.SafeExecute(rLoadCompleted, rABManifest);
        }
Exemple #4
0
        private static IEnumerator Load_Async(LoaderRequest rRequest)
        {
            string rVersionURL = rRequest.Url;

            WWWAssist.LoaderRequest rWWWVersionRequest = WWWAssist.LoadFile(rVersionURL);
            yield return(rWWWVersionRequest);

            if (rWWWVersionRequest.Bytes == null || rWWWVersionRequest.Bytes.Length == 0)
            {
                yield break;
            }

            ABVersion rVersion = new ABVersion();

            using (var ms = new MemoryStream(rWWWVersionRequest.Bytes))
            {
                using (var br = new BinaryReader(ms))
                {
                    rVersion.Deserialize(br);
                }
            }
            rRequest.Version = rVersion;
        }
Exemple #5
0
        private IEnumerator LoadManifest_Async(string rManifrestUrl)
        {
            isManifestLoadCompleted = false;

            WWW www = WWWAssist.Load(rManifrestUrl);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                isManifestLoadCompleted = true;
                yield break;
            }

            this.manifest = www.assetBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest;
            WWWAssist.Destroy(ref www);

            string[] rALLAB = this.manifest.GetAllAssetBundles();
            assetLoadInfos = new Dict <string, AssetLoadInfo>();
            for (int i = 0; i < rALLAB.Length; i++)
            {
                // 开始构建AssetLoadInfo
                AssetLoadInfo rAssetLoadInfo = new AssetLoadInfo();
                rAssetLoadInfo.abPath = rALLAB[i];
                rAssetLoadInfo.abName = rALLAB[i];
                string[] rDependABs = this.manifest.GetDirectDependencies(rALLAB[i]);
                rAssetLoadInfo.abDependNames   = rDependABs;
                rAssetLoadInfo.isLoading       = false;
                rAssetLoadInfo.isLoadCompleted = false;
                rAssetLoadInfo.cacheAsset      = null;
                rAssetLoadInfo.refCount        = 0;
                assetLoadInfos.Add(rAssetLoadInfo.abName, rAssetLoadInfo);
            }

            isManifestLoadCompleted = true;
        }
Exemple #6
0
        private IEnumerator LoadAsset_Async(LoaderRequest rRequest)
        {
            // 确认Manifest已经加载完成
            while (!isManifestLoadCompleted)
            {
                yield return(0);
            }

            AssetLoadInfo rAssetLoadInfo = null;

            if (!assetLoadInfos.TryGetValue(rRequest.path, out rAssetLoadInfo))
            {
                Debug.LogErrorFormat("找不到该资源 -- {0}", rRequest.path);
                rRequest.asset = null;
                yield break;
            }

            // 确认该资源是否已经加载完成或者正在被加载
            while (rAssetLoadInfo.isLoading && !rAssetLoadInfo.isLoadCompleted)
            {
                yield return(0);
            }

            //引用计数加1
            rAssetLoadInfo.refCount++;

            // 如果该资源加载完成了
            if (!rAssetLoadInfo.isLoading && rAssetLoadInfo.isLoadCompleted)
            {
                if (!string.IsNullOrEmpty(rRequest.assetName))
                {
                    AssetBundleRequest rABRequest = rAssetLoadInfo.cacheAsset.LoadAssetAsync(rRequest.assetName);
                    yield return(rABRequest);

                    rRequest.asset = rABRequest.asset;
                }
                yield break;
            }

            // 开始加载资源依赖项
            if (rAssetLoadInfo.abDependNames != null)
            {
                for (int i = rAssetLoadInfo.abDependNames.Length - 1; i >= 0; i--)
                {
                    string rDependABPath = rAssetLoadInfo.abDependNames[i];
                    string rDependABName = rDependABPath;

                    LoaderRequest rDependAssetRequest = new LoaderRequest(rDependABName, "", false);
                    rDependAssetRequest.Start(LoadAsset_Async(rDependAssetRequest));
                    yield return(rDependAssetRequest.Coroutine);
                }
            }

            //开始加载当前的资源包
            rAssetLoadInfo.isLoading       = true;
            rAssetLoadInfo.isLoadCompleted = false;

            string rAssetLoadUrl = AssetPlatformManager.Instance.GetStreamingUrl_CurPlatform(rAssetLoadInfo.abPath);
            WWW    www           = new WWW(rAssetLoadUrl);

            yield return(www);

            // 如果是一个直接的资源,将资源的对象取出来
            rAssetLoadInfo.cacheAsset = www.assetBundle;

            WWWAssist.Destroy(ref www);

            // 加载Object
            if (!string.IsNullOrEmpty(rRequest.assetName))
            {
                if (!rRequest.isScene)
                {
                    AssetBundleRequest rABRequest = rAssetLoadInfo.cacheAsset.LoadAssetAsync(rRequest.assetName);
                    yield return(rABRequest);

                    rRequest.asset = rABRequest.asset;
                }
                else
                {
                    rAssetLoadInfo.cacheAsset.GetAllScenePaths();
                }
            }

            rAssetLoadInfo.isLoading       = false;
            rAssetLoadInfo.isLoadCompleted = true;
        }