public override IEnumerator LoadAsync(CoroutineTasks.CoroutineWork req, Type type)
                {
                    var holdhandle = Hold();

                    try
                    {
                        if (ManiItem != null)
                        {
                            bool additive  = type != null;
                            var  sceneName = System.IO.Path.GetFileNameWithoutExtension(ManiItem.Node.PPath);
                            IsLoading = true;
                            UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded;
                            AsyncOperation raw = null;
                            try
                            {
                                raw = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, additive ? UnityEngine.SceneManagement.LoadSceneMode.Additive : UnityEngine.SceneManagement.LoadSceneMode.Single);
                            }
                            catch (Exception e)
                            {
                                PlatDependant.LogError(e);
                            }
                            if (raw != null)
                            {
                                yield return(raw);
                            }
                        }
                    }
                    finally
                    {
                        GC.KeepAlive(holdhandle);
                    }
                }
Ejemplo n.º 2
0
                public override IEnumerator LoadAsync(CoroutineTasks.CoroutineWork req, Type type)
                {
                    var holdhandle = Hold();

                    try
                    {
                        if (!Prefab)
                        {
                            if (ManiItem != null && DepBundles.Count > 0)
                            {
                                var bi = DepBundles[DepBundles.Count - 1];
                                if (bi != null && bi.Bundle != null)
                                {
                                    var path = ConcatAssetPath();
                                    while (AsyncWorkTimer.Check())
                                    {
                                        yield return(null);
                                    }

                                    AssetBundleRequest raw = null;
                                    try
                                    {
                                        raw = bi.Bundle.LoadAssetAsync <GameObject>(path);
                                    }
                                    catch (Exception e)
                                    {
                                        PlatDependant.LogError(e);
                                    }
                                    if (raw != null)
                                    {
                                        yield return(raw);

                                        var asset = raw.asset as GameObject;

                                        if (!Prefab)
                                        {
                                            Holder = null;
                                            Prefab = asset;
                                        }
                                    }
                                }
                            }
                        }
                        if (Prefab)
                        {
                            if (!Holder)
                            {
                                Holder           = Prefab.AddComponent <CapsPrefabHolder>();
                                Holder.AssetInfo = this;
                            }
                        }
                        req.Result = Prefab;
                    }
                    finally
                    {
                        GC.KeepAlive(holdhandle);
                    }
                }
 public IEnumerator LoadAsync(CoroutineTasks.CoroutineWork req, Type type)
 {
     if (Real != null)
     {
         return(Real.LoadAsync(req, type));
     }
     else
     {
         return(CoroutineRunner.GetEmptyEnumerator());
     }
 }
                private IEnumerator LoadMainAssetAsync(CoroutineTasks.CoroutineWork req)
                {
                    if (ManiItem != null && DepBundles.Count > 0)
                    {
                        var bi = DepBundles[DepBundles.Count - 1];
                        if (bi != null && bi.Bundle != null)
                        {
                            var path = ConcatAssetPath();

                            while (AsyncWorkTimer.Check())
                            {
                                yield return(null);
                            }

                            AssetBundleRequest rawreq = null;
                            try
                            {
                                rawreq = bi.Bundle.LoadAssetAsync(path);
                            }
                            catch (Exception e)
                            {
                                PlatDependant.LogError(e);
                            }
                            if (rawreq != null)
                            {
                                yield return(rawreq);

                                var asset = rawreq.asset;
                                if (asset is Texture2D)
                                {
                                    rawreq = null;
                                    try
                                    {
                                        rawreq = bi.Bundle.LoadAssetAsync(path, typeof(Sprite));
                                    }
                                    catch (Exception e)
                                    {
                                        PlatDependant.LogError(e);
                                    }
                                    if (rawreq != null)
                                    {
                                        yield return(rawreq);

                                        if (rawreq.asset)
                                        {
                                            asset = rawreq.asset;
                                        }
                                    }
                                }
                                req.Result = asset;
                            }
                        }
                    }
                }
                public override IEnumerator LoadAsync(CoroutineTasks.CoroutineWork req, Type type)
                {
                    var holdhandle = Hold();

                    try
                    {
                        while (AsyncWorkTimer.Check())
                        {
                            yield return(null);
                        }

                        if (MainType == null)
                        {
                            var mainwork = new CoroutineTasks.CoroutineWorkSingle();
                            mainwork.SetWork(LoadMainAssetAsync(mainwork));
                            mainwork.StartCoroutine();

                            while (true)
                            {
                                if (MainType != null)
                                {
                                    mainwork.Dispose();
                                    break;
                                }
                                if (mainwork.Done)
                                {
                                    var asset = mainwork.Result as Object;
                                    if (!asset)
                                    {
                                        MainType = typeof(object);
                                    }
                                    else
                                    {
                                        MainType = asset.GetType();
                                        TypedAssets[MainType] = new AssetRef()
                                        {
                                            Asset = new WeakReference(asset)
                                        };
                                    }
                                    if (MainType == typeof(object) || type == null || type.IsAssignableFrom(MainType))
                                    {
                                        req.Result = asset;
                                        yield break;
                                    }
                                }
                            }
                        }
                        if (MainType == typeof(object))
                        {
                            yield break;
                        }
                        else if (type == null || type.IsAssignableFrom(MainType))
                        {
                            type = MainType;
                        }

                        AssetRef rAsset;
                        if (TypedAssets.TryGetValue(type, out rAsset))
                        {
                            if (rAsset.Asset != null)
                            {
                                var asset = rAsset.Asset.GetWeakReference <Object>();
                                if (asset)
                                {
                                    req.Result = asset;
                                    yield break;
                                }
                            }
                        }

                        while (AsyncWorkTimer.Check())
                        {
                            yield return(null);
                        }
                        if (rAsset == null)
                        {
                            rAsset            = new AssetRef();
                            TypedAssets[type] = rAsset;
                        }
                        rAsset.Asset = null;

                        if (ManiItem != null && DepBundles.Count > 0)
                        {
                            var bi = DepBundles[DepBundles.Count - 1];
                            if (bi != null && bi.Bundle != null)
                            {
                                var path = ConcatAssetPath();

                                AssetBundleRequest reqraw = null;
                                try
                                {
                                    reqraw = bi.Bundle.LoadAssetAsync(path, type);
                                }
                                catch (Exception e)
                                {
                                    PlatDependant.LogError(e);
                                }
                                if (reqraw != null)
                                {
                                    yield return(reqraw);

                                    var asset = reqraw.asset;

                                    if (!asset)
                                    {
                                        yield break;
                                    }

                                    rAsset.Asset = new WeakReference(asset);
                                    req.Result   = asset;
                                }
                            }
                        }
                    }
                    finally
                    {
                        GC.KeepAlive(holdhandle);
                    }
                }
            private static IEnumerator LoadAssetAsyncWork(CoroutineTasks.CoroutineWork req, string asset, Type type)
            {
                while (AsyncWorkTimer.Check())
                {
                    yield return(null);
                }
                while (ResManager.IsCollectingGarbage)
                {
                    yield return(null);
                }
                ResManager.DelayGarbageCollectTo(System.Environment.TickCount + 10000);

#if COMPATIBLE_RESMANAGER_V1
                asset = CompatibleAssetName(asset);
#endif
                CapsResManifestNode node;
                if (CollapsedManifest.TryGetItem(asset, out node) && node.Item != null)
                {
                    var sceneitem = node.Item;
                    while (sceneitem.Ref != null)
                    {
                        sceneitem = sceneitem.Ref;
                    }
                    var scenepath = sceneitem.Node.GetFullPath();
                    int sceneindex;
                    if (IsBuiltinScene(scenepath, out sceneindex))
                    {
                        if (sceneindex >= 0)
                        {
                            yield return(UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneindex, type == null ? UnityEngine.SceneManagement.LoadSceneMode.Single : UnityEngine.SceneManagement.LoadSceneMode.Additive));
                        }
                        else
                        {
                            yield return(UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(node.PPath), type == null ? UnityEngine.SceneManagement.LoadSceneMode.Single : UnityEngine.SceneManagement.LoadSceneMode.Additive));
                        }
                        ResManager.DelayGarbageCollectTo(int.MinValue);
                        //req.Result = ???
                        yield break;
                    }
                    var item = node.Item;
                    var ai   = CreateAssetInfo(item);
                    ResManager.DelayGarbageCollectTo(System.Environment.TickCount + 10000);
                    yield return(ai.PreloadAsync());

                    ResManager.DelayGarbageCollectTo(System.Environment.TickCount + 10000);
                    var work = new CoroutineTasks.CoroutineWorkSingle();
                    work.SetWork(ai.LoadAsync(work, type));
                    yield return(work);

                    req.Result = work.Result;
                }
                else
                {
                    int sceneindex;
                    if (IsBuiltinScene(asset, out sceneindex))
                    {
                        if (sceneindex >= 0)
                        {
                            yield return(UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneindex, type == null ? UnityEngine.SceneManagement.LoadSceneMode.Single : UnityEngine.SceneManagement.LoadSceneMode.Additive));
                        }
                        else
                        {
                            yield return(UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(asset), type == null ? UnityEngine.SceneManagement.LoadSceneMode.Single : UnityEngine.SceneManagement.LoadSceneMode.Additive));
                        }
                        ResManager.DelayGarbageCollectTo(int.MinValue);
                        //req.Result = ???
                        yield break;
                    }
                }

                ResManager.DelayGarbageCollectTo(int.MinValue);
            }
 public abstract IEnumerator LoadAsync(CoroutineTasks.CoroutineWork req, Type type);