void StartDownload()
        {
            this.startCount = 0;

            this.lastError        = LastErrorCode.OK;
            this.lastErrorMessage = "OK";

            if (this.currentDownloads.Count > 0)
            {
                Debug.LogWarning("downloading is in progress, stop all");
                foreach (var c in this.currentDownloads)
                {
                    StopCoroutine(c);
                }

                this.currentDownloads.Clear();
            }

            //first we should unload all assets and all loaded objects,
            //we need refresh objects in asset bundles
            foreach (var b in this.CurrentAssetBundles)
            {
                if (b == null)
                {
                    Debug.LogWarning("CurrentAssetBundles has null asset");
                }
                b?.Unload(true);
            }
            this.CurrentAssetBundles.Clear();


            this.currentDownloads.Add(StartCoroutine(this.GetAssetBundleManifest()));
        }
        private IEnumerator GetBundle(string name, Hash128 hash)
        {
            startCount++;
            //download one AssetBundle and add to current bundle list
            var www = UnityWebRequestAssetBundle.GetAssetBundle(this.syncServer + "/" + name, hash, 0);

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                this.lastError        = LastErrorCode.ERROR;
                this.lastErrorMessage = www.error;
            }
            else
            {
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
                if (!this.CurrentAssetBundles.Contains(bundle))
                {
                    this.CurrentAssetBundles.Add(bundle);
                    this.lastErrorMessage += " " + hash;
                    Debug.LogFormat("Bundle added {0}", bundle.name);
                }
            }


            //Debug.LogFormat("GetBundle done");
            startCount--;
            yield return(0);
        }
示例#3
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (IsAuthor != false)
            {
                hash ^= IsAuthor.GetHashCode();
            }
            if (ReconnectCount != 0)
            {
                hash ^= ReconnectCount.GetHashCode();
            }
            if (LastErrorCode != 0)
            {
                hash ^= LastErrorCode.GetHashCode();
            }
            if (EnterRoomAttach.Length != 0)
            {
                hash ^= EnterRoomAttach.GetHashCode();
            }
            if (ClientLiveSdkVersion.Length != 0)
            {
                hash ^= ClientLiveSdkVersion.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        private IEnumerator GetAssetBundleManifest()
        {
            startCount++;
            //download special AssetsBundles first to get AssetBundleManifest
            var www = UnityWebRequestAssetBundle.GetAssetBundle(this.syncServer + "/PackedAssetBundle");

            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
                this.lastError        = LastErrorCode.ERROR;
                this.lastErrorMessage = www.error;
            }
            else
            {
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
                if (bundle != null)
                {
                    if (this.currentManifest != null)
                    {
                        DestroyImmediate(this.currentManifest, true);
                        this.currentManifest = null;
                    }
                    this.currentManifest = bundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
                    Debug.LogFormat("Manifest {0}", this.currentManifest?.name);

                    //we need manifest for later
                    bundle.Unload(false);

                    var co = StartCoroutine(this.GetAssetBundles());
                    this.currentDownloads.Add(co);
                    yield return(co);
                }
            }
            //Debug.LogFormat("Manifest done");
            startCount--;

            //it is not necessary that using startCount to trace this
            //because  yield return Coroutine will do same thing
            //just for double safety.
            if (startCount == 0)
            {
                if (this.lastError == LastErrorCode.OK)
                {
                    Debug.LogFormat("download done");
                    this.OnFinishDownload?.Invoke(this, new AssetBundleEventArg()
                    {
                        message = this.lastErrorMessage
                    });
                }
                else
                {
                    Debug.LogFormat("download Error {0}", this.lastErrorMessage);
                    this.OnDownloadError?.Invoke(this, new AssetBundleEventArg()
                    {
                        message = this.lastErrorMessage
                    });
                }
            }
            else
            {
                Debug.Log("startCount Error");
            }
            yield return(0);
        }