Beispiel #1
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);
                    }
                }
                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;
                            }
                        }
                    }
                }
Beispiel #3
0
        public static IEnumerator InitAsync(ProgressReportDelegate reportProgress)
        {
            if (reportProgress != null)
            {
                reportProgress("Desc", "Startup", 0);
            }
            AsyncWorkTimer.Check();

            var list = _InitList;

            if (list != null)
            {
                list.Sort((ia, ib) => ia.Order - ib.Order);
                int   totalStep  = 0;
                int   totalPhase = 0;
                int[] workSteps  = null;
                if (reportProgress != null)
                {
                    workSteps = new int[list.Count];
                    for (int i = 0; i < list.Count; ++i)
                    {
                        var pr = list[i] as IInitProgressReporter;
                        if (pr != null && pr is IInitAsync)
                        {
                            pr.ReportProgress += reportProgress;
                            var step = pr.CountWorkStep();
                            totalStep += step;
                            ++totalPhase;
                            workSteps[i] = step;
                        }
                        else
                        {
                            list[i].Prepare();
                        }
                    }
                    if (totalStep > 0)
                    {
                        reportProgress("HaveWorkToDo", null, 1);
                    }
                    reportProgress("TotalPhase", null, totalPhase);
                    reportProgress("TotalStep", null, totalStep);
                    reportProgress("WorkingPhase", null, 0);
                    reportProgress("WorkingStep", null, 0);
                }
                else
                {
                    for (int i = 0; i < list.Count; ++i)
                    {
                        list[i].Prepare();
                    }
                }
                int workingPhase = 0;
                int workingStep  = 0;
                for (int i = 0; i < list.Count; ++i)
                {
                    var init  = list[i];
                    var inita = init as IInitAsync;
                    if (inita != null)
                    {
                        if (AsyncWorkTimer.Check())
                        {
                            yield return(null);
                        }
                        if (reportProgress != null)
                        {
                            var pr = init as IInitProgressReporter;
                            if (pr != null)
                            {
                                reportProgress("WorkingPhase", null, ++workingPhase);
                                reportProgress("Desc", pr.GetPhaseDesc(), 0);
                            }
                        }
                        var work = inita.InitAsync();
                        yield return(work);

                        if (reportProgress != null)
                        {
                            if (workSteps[i] > 0)
                            {
                                workingStep += workSteps[i];
                                reportProgress("WorkingStep", null, workingStep);
                            }
                        }
                    }
                    else
                    {
                        list[i].Init();
                    }
                }
                if (reportProgress != null)
                {
                    for (int i = 0; i < list.Count; ++i)
                    {
                        var pr = list[i] as IInitProgressReporter;
                        if (pr != null && pr is IInitAsync)
                        {
                            pr.ReportProgress -= reportProgress;
                        }
                    }
                    reportProgress("AllDone", null, 1);
                }
            }
        }
        private static IEnumerator LoadFromResourceWork(CoroutineWork req, string name, Type type)
        {
            if (req.Result != null)
            {
                yield break;
            }
            while (AsyncWorkTimer.Check())
            {
                yield return(null);
            }
            if (!string.IsNullOrEmpty(name))
            {
                var ext = System.IO.Path.GetExtension(name);
                name = name.Substring(0, name.Length - ext.Length);

                string[] distributeFlags = GetValidDistributeFlags();
                if (distributeFlags != null)
                {
                    for (int i = distributeFlags.Length - 1; i >= 0; --i)
                    {
                        while (AsyncWorkTimer.Check())
                        {
                            yield return(null);
                        }

                        var             flag   = distributeFlags[i];
                        ResourceRequest rawreq = null;
                        if (type == null)
                        {
                            try
                            {
                                rawreq = Resources.LoadAsync("dist/" + flag + "/" + name);
                            }
                            catch (Exception e)
                            {
                                PlatDependant.LogError(e);
                            }
                        }
                        else
                        {
                            try
                            {
                                rawreq = Resources.LoadAsync("dist/" + flag + "/" + name, type);
                            }
                            catch (Exception e)
                            {
                                PlatDependant.LogError(e);
                            }
                        }
                        if (rawreq != null)
                        {
                            yield return(rawreq);

                            if (rawreq.asset != null)
                            {
                                req.Result = rawreq.asset;
                                if (type == null && rawreq.asset is Texture2D)
                                {
                                    rawreq = null;
                                    try
                                    {
                                        rawreq = Resources.LoadAsync("dist/" + flag + "/" + name, typeof(Sprite));
                                    }
                                    catch (Exception e)
                                    {
                                        PlatDependant.LogError(e);
                                    }
                                    if (rawreq != null)
                                    {
                                        yield return(rawreq);

                                        if (rawreq.asset != null)
                                        {
                                            req.Result = rawreq.asset;
                                        }
                                    }
                                }
                                yield break;
                            }
                        }
                    }
                }
                {
                    while (AsyncWorkTimer.Check())
                    {
                        yield return(null);
                    }
                    ResourceRequest rawreq = null;
                    if (type == null)
                    {
                        try
                        {
                            rawreq = Resources.LoadAsync(name);
                        }
                        catch (Exception e)
                        {
                            PlatDependant.LogError(e);
                        }
                    }
                    else
                    {
                        try
                        {
                            rawreq = Resources.LoadAsync(name, type);
                        }
                        catch (Exception e)
                        {
                            PlatDependant.LogError(e);
                        }
                    }
                    if (rawreq != null)
                    {
                        yield return(rawreq);

                        if (rawreq.asset != null)
                        {
                            req.Result = rawreq.asset;
                            if (type == null && rawreq.asset is Texture2D)
                            {
                                rawreq = null;
                                try
                                {
                                    rawreq = Resources.LoadAsync(name, typeof(Sprite));
                                }
                                catch (Exception e)
                                {
                                    PlatDependant.LogError(e);
                                }
                                if (rawreq != null)
                                {
                                    yield return(rawreq);

                                    if (rawreq.asset != null)
                                    {
                                        req.Result = rawreq.asset;
                                    }
                                }
                            }
                            yield break;
                        }
                    }
                }
            }
        }
            public IEnumerator InitAsync(bool async)
            {
                if (_PackageVer > 0 || _ObbVer > 0)
                {
                    if (_RunningVer == null)
                    {
                        // delete all existing.
                        if (_PendingFiles != null)
                        {
                            for (int i = 0; i < _PendingFiles.Length; ++i)
                            {
                                if (async && AsyncWorkTimer.Check())
                                {
                                    yield return(null);
                                }
                                var file = _PendingFiles[i];
                                PlatDependant.DeleteFile(file);
                                ReportProgress("WorkingStepAdvance", null, 0);
                            }
                        }
                        if (_UpdateFiles != null)
                        {
                            for (int i = 0; i < _UpdateFiles.Length; ++i)
                            {
                                if (async && AsyncWorkTimer.Check())
                                {
                                    yield return(null);
                                }
                                var file = _UpdateFiles[i];
                                PlatDependant.DeleteFile(file);
                                ReportProgress("WorkingStepAdvance", null, 0);
                            }
                        }
                        if (Application.platform == RuntimePlatform.Android)
                        {
                            if (!ResManager.LoadAssetsFromApk)
                            {
                                var arch = ResManager.AndroidApkZipArchive;
                                if (arch != null)
                                {
                                    var entries = arch.Entries;
                                    for (int i = 0; i < entries.Count; ++i)
                                    {
                                        if (async && AsyncWorkTimer.Check())
                                        {
                                            yield return(null);
                                        }
                                        try
                                        {
                                            var entry = entries[i];
                                            var name  = entry.FullName;
                                            if (name.StartsWith("assets/res/") && name != "assets/res/version.txt")
                                            {
                                                // copy
                                                using (var src = entry.Open())
                                                {
                                                    using (var dst = PlatDependant.OpenWrite(ThreadSafeValues.UpdatePath + "/" + name.Substring("assets/".Length)))
                                                    {
                                                        src.CopyTo(dst);
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            PlatDependant.LogError(e);
                                        }
                                        ReportProgress("WorkingStepAdvance", null, 0);
                                    }
                                }
                            }
                            {
                                var arch = ResManager.ObbZipArchive;
                                if (arch != null)
                                {
                                    var entries = arch.Entries;
                                    for (int i = 0; i < entries.Count; ++i)
                                    {
                                        if (async && AsyncWorkTimer.Check())
                                        {
                                            yield return(null);
                                        }
                                        try
                                        {
                                            var entry = entries[i];
                                            var name  = entry.FullName;
                                            if (name.StartsWith("res/") && name != "res/version.txt")
                                            {
                                                if (!ResManager.LoadAssetsFromObb || entry.CompressedLength != entry.Length)
                                                {
                                                    // copy
                                                    using (var src = entry.Open())
                                                    {
                                                        using (var dst = PlatDependant.OpenWrite(ThreadSafeValues.UpdatePath + "/" + name))
                                                        {
                                                            src.CopyTo(dst);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            PlatDependant.LogError(e);
                                        }
                                        ReportProgress("WorkingStepAdvance", null, 0);
                                    }
                                }
                            }
                        }
                        // write version
                        var finalVersions = new Dictionary <string, int>();
                        if (_PackageResKeys != null)
                        {
                            for (int i = 0; i < _PackageResKeys.Count; ++i)
                            {
                                finalVersions[_PackageResKeys[i]] = _PackageVer;
                            }
                        }
                        if (_ObbResKeys != null)
                        {
                            for (int i = 0; i < _ObbResKeys.Count; ++i)
                            {
                                finalVersions[_ObbResKeys[i]] = _ObbVer;
                            }
                        }
                        var versionfile    = ThreadSafeValues.UpdatePath + "/res/ver.txt";
                        var versionfiletmp = versionfile + ".tmp";
                        using (var sw = PlatDependant.OpenWriteText(versionfiletmp))
                        {
                            foreach (var kvpver in finalVersions)
                            {
                                sw.Write(kvpver.Key);
                                sw.Write("|");
                                sw.Write(kvpver.Value);
                                sw.WriteLine();
                            }
                            sw.Flush();
                        }
                        PlatDependant.MoveFile(versionfiletmp, versionfile);
                        yield break;
                    }
                    else if (_OldRunningKeys != null && _OldRunningKeys.Count > 0)
                    {
                        // delete old existing.
                        if (_PendingFiles != null)
                        {
                            string pverfile     = ThreadSafeValues.UpdatePath + "/pending/res/ver.txt";
                            bool   pendingready = PlatDependant.IsFileExist(pverfile);
                            if (pendingready)
                            {
                                for (int i = 0; i < _PendingFiles.Length; ++i)
                                {
                                    if (async && AsyncWorkTimer.Check())
                                    {
                                        yield return(null);
                                    }
                                    var file = _PendingFiles[i];
                                    var part = file.Substring(ThreadSafeValues.UpdatePath.Length + "/pending/res/".Length);
                                    if (IsResFileOld(part))
                                    {
                                        PlatDependant.DeleteFile(file);
                                    }
                                    else
                                    {
                                        if (part != "ver.txt")
                                        {
                                            PlatDependant.MoveFile(file, ThreadSafeValues.UpdatePath + "/res/" + part);
                                        }
                                    }
                                    ReportProgress("WorkingStepAdvance", null, 0);
                                }
                                PlatDependant.DeleteFile(pverfile);
                            }
                            else
                            {
                                for (int i = 0; i < _PendingFiles.Length; ++i)
                                {
                                    if (async && AsyncWorkTimer.Check())
                                    {
                                        yield return(null);
                                    }
                                    var file = _PendingFiles[i];
                                    PlatDependant.DeleteFile(file);
                                    ReportProgress("WorkingStepAdvance", null, 0);
                                }
                            }
                        }
                        if (_UpdateFiles != null)
                        {
                            for (int i = 0; i < _UpdateFiles.Length; ++i)
                            {
                                if (async && AsyncWorkTimer.Check())
                                {
                                    yield return(null);
                                }
                                var file = _UpdateFiles[i];
                                var part = file.Substring(ThreadSafeValues.UpdatePath.Length + "/res/".Length);
                                if (IsResFileOld(part))
                                {
                                    PlatDependant.DeleteFile(file);
                                }
                                ReportProgress("WorkingStepAdvance", null, 0);
                            }
                        }
                        if (Application.platform == RuntimePlatform.Android)
                        {
                            if (!ResManager.LoadAssetsFromApk)
                            {
                                var arch = ResManager.AndroidApkZipArchive;
                                if (arch != null)
                                {
                                    var entries = arch.Entries;
                                    for (int i = 0; i < entries.Count; ++i)
                                    {
                                        if (async && AsyncWorkTimer.Check())
                                        {
                                            yield return(null);
                                        }
                                        try
                                        {
                                            var entry = entries[i];
                                            var name  = entry.FullName;
                                            if (name.StartsWith("assets/res/") && name != "assets/res/version.txt")
                                            {
                                                var part = name.Substring("assets/res/".Length);
                                                if (IsResFileOld(part))
                                                {
                                                    // copy
                                                    using (var src = entry.Open())
                                                    {
                                                        using (var dst = PlatDependant.OpenWrite(ThreadSafeValues.UpdatePath + "/res/" + part))
                                                        {
                                                            src.CopyTo(dst);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            PlatDependant.LogError(e);
                                        }
                                        ReportProgress("WorkingStepAdvance", null, 0);
                                    }
                                }
                            }
                            {
                                var arch = ResManager.ObbZipArchive;
                                if (arch != null)
                                {
                                    var entries = arch.Entries;
                                    for (int i = 0; i < entries.Count; ++i)
                                    {
                                        if (async && AsyncWorkTimer.Check())
                                        {
                                            yield return(null);
                                        }
                                        try
                                        {
                                            var entry = entries[i];
                                            var name  = entry.FullName;
                                            if (name.StartsWith("res/") && name != "res/version.txt")
                                            {
                                                if (!ResManager.LoadAssetsFromObb || entry.CompressedLength != entry.Length)
                                                {
                                                    var part = name.Substring("res/".Length);
                                                    if (IsResFileOld(part))
                                                    {
                                                        // copy
                                                        using (var src = entry.Open())
                                                        {
                                                            using (var dst = PlatDependant.OpenWrite(ThreadSafeValues.UpdatePath + "/" + name))
                                                            {
                                                                src.CopyTo(dst);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            PlatDependant.LogError(e);
                                        }
                                        ReportProgress("WorkingStepAdvance", null, 0);
                                    }
                                }
                            }
                        }
                        // write version
                        var finalVersions = new Dictionary <string, int>(_RunningVer);
                        if (_PackageResKeys != null)
                        {
                            for (int i = 0; i < _PackageResKeys.Count; ++i)
                            {
                                var key = _PackageResKeys[i];
                                if (_OldRunningKeys.Contains(key))
                                {
                                    finalVersions[key] = _PackageVer;
                                }
                            }
                        }
                        if (_ObbResKeys != null)
                        {
                            for (int i = 0; i < _ObbResKeys.Count; ++i)
                            {
                                var key = _ObbResKeys[i];
                                if (_OldRunningKeys.Contains(key))
                                {
                                    finalVersions[key] = _ObbVer;
                                }
                            }
                        }
                        var versionfile    = ThreadSafeValues.UpdatePath + "/res/ver.txt";
                        var versionfiletmp = versionfile + ".tmp";
                        using (var sw = PlatDependant.OpenWriteText(versionfiletmp))
                        {
                            foreach (var kvpver in finalVersions)
                            {
                                sw.Write(kvpver.Key);
                                sw.Write("|");
                                sw.Write(kvpver.Value);
                                sw.WriteLine();
                            }
                            sw.Flush();
                        }
                        PlatDependant.MoveFile(versionfiletmp, versionfile);
                        yield break;
                    }
                }

                // All running version is new
                // move pending update
                if (_PendingFiles != null)
                {
                    string pverfile     = ThreadSafeValues.UpdatePath + "/pending/res/ver.txt";
                    bool   pendingready = PlatDependant.IsFileExist(pverfile);
                    for (int i = 0; i < _PendingFiles.Length; ++i)
                    {
                        if (async && AsyncWorkTimer.Check())
                        {
                            yield return(null);
                        }
                        var file = _PendingFiles[i];
                        if (pendingready)
                        {
                            var part = file.Substring(ThreadSafeValues.UpdatePath.Length + "/pending/res/".Length);
                            if (part != "ver.txt")
                            {
                                PlatDependant.MoveFile(file, ThreadSafeValues.UpdatePath + "/res/" + part);
                            }
                        }
                        else
                        {
                            PlatDependant.DeleteFile(file);
                        }
                        ReportProgress("WorkingStepAdvance", null, 0);
                    }
                    PlatDependant.DeleteFile(pverfile);
                    if (_RunningVer != null && pendingready)
                    {
                        // write version
                        var versionfile    = ThreadSafeValues.UpdatePath + "/spt/ver.txt";
                        var versionfiletmp = versionfile + ".tmp";
                        using (var sw = PlatDependant.OpenWriteText(versionfiletmp))
                        {
                            foreach (var kvpver in _RunningVer)
                            {
                                sw.Write(kvpver.Key);
                                sw.Write("|");
                                sw.Write(kvpver.Value);
                                sw.WriteLine();
                            }
                            sw.Flush();
                        }
                        PlatDependant.MoveFile(versionfiletmp, versionfile);
                    }
                }
            }
                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 virtual IEnumerator PreloadAsync()
                {
                    if (_PreloadReady)
                    {
                        for (int i = 0; i < DepBundles.Count; ++i)
                        {
                            var bi = DepBundles[i];
                            if (bi == null || bi.Bundle == null)
                            {
                                _PreloadReady = false;
                                break;
                            }
                        }
                        if (_PreloadReady)
                        {
                            yield break;
                        }
                    }

                    List <AssetBundleInfo> bundles = new List <AssetBundleInfo>();

                    try
                    {
                        var opmod = ManiItem.Manifest.MFlag;
                        var mod   = opmod;
                        if (ManiItem.Manifest.InMain)
                        {
                            mod = "";
                        }

                        string bundle = ManiItem.BRef;
                        if (string.IsNullOrEmpty(bundle))
                        {
                            bundle = FormatBundleName();
                        }

                        var cabi = LoadAssetBundleEx(mod, bundle, true);
                        if (cabi != null)
                        {
                            cabi.AddRef();
                            bundles.Add(cabi);
                            while (AsyncWorkTimer.Check())
                            {
                                yield return(null);
                            }
                            if (_PreloadReady)
                            {
                                yield break;
                            }

                            AssetBundleManifest umani;
                            if (UnityManifests.TryGetValue(mod, out umani) && umani)
                            {
                                var deps = umani.GetAllDependencies(bundle);
                                if (deps != null)
                                {
                                    for (int i = 0; i < deps.Length; ++i)
                                    {
                                        var dep = deps[i];
                                        var bi  = LoadAssetBundleEx(mod, dep, false);
                                        if (bi != null)
                                        {
                                            bi.AddRef();
                                            bundles.Insert(bundles.Count - 1, bi);
                                            while (AsyncWorkTimer.Check())
                                            {
                                                yield return(null);
                                            }
                                            if (_PreloadReady)
                                            {
                                                yield break;
                                            }
                                        }
                                    }
                                }
                            }

                            for (int i = 0; i < DepBundles.Count; ++i)
                            {
                                var bi = DepBundles[i];
                                if (bi != null)
                                {
                                    bi.Release();
                                }
                            }
                            DepBundles.Clear();
                            DepBundles.AddRange(bundles);
                            bundles.Clear();
                            _PreloadReady = true;
                        }
                    }
                    finally
                    {
                        if (bundles != null)
                        {
                            for (int i = 0; i < bundles.Count; ++i)
                            {
                                bundles[i].Release();
                            }
                        }
                    }
                }