protected void LoadAsset(bool useWWW, bool fromCache, bool sync)
 {
     SyncTask.Create(
         this.LoadAssetInternal(
             this._isManifest ? this.assetBundleName : AssetsManager.RemapVariantName(this.assetBundleName),
             this.assetName, useWWW, fromCache, sync));
 }
Exemple #2
0
 public void BeginSceneActivation(CompleteHandler callback, object param = null)
 {
     if (this._asyncOperation != null)
     {
         SyncTask.Create(this.HandleSceneActivation(callback, param));
     }
 }
        public virtual void Load(AssetsCompleteHandler completeHandler, ProgressHandler progressHandler,
                                 ErrorHandler errorHandler, bool useWWW = false, bool fromCache = true, bool sync = false)
        {
            this.completeHandler = completeHandler;
            this.progressHandler = progressHandler;
            this.errorHandler    = errorHandler;

            AssetsProxy assetsProxy = AssetsManager.GetAssetBundle(this.assetBundleName);

            if (assetsProxy != null)
            {
                this.completeHandler?.Invoke(this, assetsProxy);
                return;
            }

            if (Application.isEditor)
            {
                fromCache = false;
            }

            this._canceled = false;

            if (!this._isManifest)
            {
                string[] dependencies = GAssetBundleManifest.GetAllDependencies(this.assetBundleName);
                if (dependencies != null &&
                    dependencies.Length > 0)
                {
                    int           count = dependencies.Length;
                    List <string> dependenciesNotLoaded = new List <string>();
                    for (int i = 0; i < count; i++)
                    {
                        dependencies[i] = AssetsManager.RemapVariantName(dependencies[i]);
                        AssetsProxy dAssetsProxy = AssetsManager.GetAssetBundle(dependencies[i]);
                        if (dAssetsProxy == null)
                        {
                            dependenciesNotLoaded.Add(dependencies[i]);
                        }
                    }
                    if (dependenciesNotLoaded.Count == 0)
                    {
                        this.LoadAsset(useWWW, fromCache, sync);
                    }
                    else
                    {
                        SyncTask.Create(this.LoadDependenciesInternal(dependenciesNotLoaded, useWWW, fromCache, sync));
                    }
                }
                else
                {
                    this.LoadAsset(useWWW, fromCache, sync);
                }
            }
            else
            {
                this.LoadAsset(useWWW, fromCache, sync);
            }
        }
Exemple #4
0
        private IEnumerator LoadSceneAsync(string assetName, LoadSceneMode loadSceneMode, bool sync)
        {
            if (sync)
            {
                SceneManager.LoadScene(assetName, loadSceneMode);
            }
            else
            {
                yield return(SyncTask.Create(this.HandleLoadSceneAsync(assetName)));
            }

            this.progressHandler?.Invoke(this, 1f);
            this.completeHandler?.Invoke(this, null);
        }
Exemple #5
0
        public override void Load(AssetsCompleteHandler completeHandler, ProgressHandler progressHandler,
                                  ErrorHandler errorHandler, bool useWWW = false, bool fromCache = true, bool sync = false)
        {
            this.completeHandler = completeHandler;
            this.progressHandler = progressHandler;
            this.errorHandler    = errorHandler;
            this._canceled       = false;

            if (string.IsNullOrEmpty(this.assetBundleName))
            {
                SyncTask.Create(this.LoadSceneAsync(this.assetName, this._loadSceneMode, sync));
            }
            else
            {
                if (Application.isEditor)
                {
                    fromCache = false;
                }
                string[] dependencies = GAssetBundleManifest.GetAllDependencies(this.assetBundleName);
                if (dependencies != null &&
                    dependencies.Length > 0)
                {
                    int           count = dependencies.Length;
                    List <string> dependenciesNotLoaded = new List <string>();
                    for (int i = 0; i < count; i++)
                    {
                        dependencies[i] = AssetsManager.RemapVariantName(dependencies[i]);
                        AssetsProxy dAssetsProxy = AssetsManager.GetAssetBundle(dependencies[i]);
                        if (dAssetsProxy == null)
                        {
                            dependenciesNotLoaded.Add(dependencies[i]);
                        }
                    }
                    if (dependenciesNotLoaded.Count == 0)
                    {
                        this.LoadAsset(useWWW, fromCache, sync);
                    }
                    else
                    {
                        SyncTask.Create(this.LoadDependenciesInternal(dependenciesNotLoaded, useWWW, fromCache, sync));
                    }
                }
                else
                {
                    this.LoadAsset(useWWW, fromCache, sync);
                }
            }
        }
Exemple #6
0
        public void Enter(object param)
        {
            NetModule.instance.AddACMDListener(Module.BATTLE, Command.ACMD_ENTER_BATTLE, this.OnEnterBattle);
            NetModule.instance.AddQCMDListener(Module.ROOM, Command.QCMD_MAP_READY, this.OnMapReadyResult);

            this._root = UIPackage.CreateObject("cutscene", "Main").asCom;
            GRoot.inst.AddChild(this._root);
            this._root.size = GRoot.inst.size;

            GProgressBar bar = this._root["bar"].asProgress;

            bar.value    = 0;
            bar.minValue = 0;
            bar.maxValue = 1;

            //preload here
            _DTO_begin_fight dto = ( _DTO_begin_fight )param;

            SyncTask.Create(this.StartLoad(dto));
        }
 public static void Load()
 {
     SyncTask.Create(StartLoad(_cid, _image, _map));
 }
Exemple #8
0
        protected override IEnumerator LoadAssetInternal(string assetBundleName, string level, bool useWWW, bool fromCache, bool sync)
        {
            while (AssetsManager.IsLoadingLocked(assetBundleName))
            {
                yield return(0);
            }

            AssetsManager.LockLoading(assetBundleName);

            if (useWWW)
            {
                string url = AssetsManager.relativeResUrl + assetBundleName;
                WWW    www = fromCache && !this._isManifest
                                                          ? WWW.LoadFromCacheOrDownload(url, GAssetBundleManifest.GetAssetBundleHash(assetBundleName), 0)
                                                          : new WWW(url);

                ++AssetsManager.numLoading;

                while (!www.isDone)
                {
                    if (this._canceled)
                    {
                        --AssetsManager.numLoading;
                        AssetsManager.UnlockLoading(assetBundleName);
                        yield break;
                    }
                    this.progressHandler?.Invoke(this, www.progress * 0.9f * 0.7f + 0.3f);
                    yield return(0);
                }

                --AssetsManager.numLoading;

                if (this._canceled)
                {
                    www.Dispose();
                    AssetsManager.UnlockLoading(assetBundleName);
                    yield break;
                }

                this.progressHandler?.Invoke(this, 0.9f * 0.7f + 0.3f);

                if (!string.IsNullOrEmpty(www.error))
                {
                    this.errorHandler?.Invoke(this, www.error);
                }
                else
                {
                    AssetBundle assetBundle = www.assetBundle;                     //必须先载入到内存

                    if (sync)
                    {
                        SceneManager.LoadScene(level, this._loadSceneMode);
                    }
                    else
                    {
                        yield return(SyncTask.Create(this.HandleLoadSceneAsync(level)));
                    }

                    www.assetBundle.Unload(false);
                }
                www.Dispose();
            }
            else
            {
                AssetBundle assetBundle;
                string      url = AssetsManager.relativeResPath + assetBundleName;
                if (sync)
                {
                    assetBundle = AssetBundle.LoadFromFile(url);
                }
                else
                {
                    AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(url);
                    assetBundleCreateRequest.allowSceneActivation = false;
                    while (!assetBundleCreateRequest.isDone)
                    {
                        if (this._canceled)
                        {
                            AssetsManager.UnlockLoading(assetBundleName);
                            yield break;
                        }
                        this.progressHandler?.Invoke(this, assetBundleCreateRequest.progress * 0.9f * 0.7f + 0.3f);
                        yield return(0);
                    }
                    assetBundle = assetBundleCreateRequest.assetBundle;
                }

                this.progressHandler?.Invoke(this, 0.9f * 0.7f + 0.3f);

                if (assetBundle == null)
                {
                    this.errorHandler?.Invoke(this, $"Failed to load {url}!");
                }
                else
                {
                    if (sync)
                    {
                        SceneManager.LoadScene(level, this._loadSceneMode);
                    }
                    else
                    {
                        yield return(SyncTask.Create(this.HandleLoadSceneAsync(level)));
                    }

                    this.progressHandler?.Invoke(this, 1f);
                    this.completeHandler?.Invoke(this, null);
                    assetBundle.Unload(false);
                }
            }

            AssetsManager.UnlockLoading(assetBundleName);
        }
Exemple #9
0
        public static void UnloadScene(Scene scene, CompleteHandler completeCallback, object param = null)
        {
            AsyncOperation ao = SceneManager.UnloadSceneAsync(scene);

            SyncTask.Create(HandleUnloadScene(ao, completeCallback, param));
        }