Example #1
0
        public async Task <AssetRef> LoadAsync(string path, TYPE type)
        {
            var option = new LoadingOption()
            {
                block = true, allowSceneActivation = false,
            };

            return(await LoadAsync(path, type, option, ""));
        }
Example #2
0
        protected async Task <AssetRef> LoadAssetBundleAsync(string path, LoadingOption option)
        {
            var assetBundleRef = FindAssetRef(path);

            if (assetBundleRef != null)
            {
                Log.Resource.I("LoadAssetBundleAsync {0} in Cache", path);
                return(assetBundleRef);
            }

            Log.Resource.I("LoadAssetBundleAsync {0}", path);
            return(await LoadAssetBundleAndDepencenciesAsync(path, option));
        }
Example #3
0
        public virtual async Task <AssetRef> LoadAsync(string path, TYPE type, LoadingOption option, string assetBundlePath)
        {
            path = Core.Path.instance.Resolve(path, type);
            var name     = System.IO.Path.GetFileNameWithoutExtension(path);
            var assetRef = FindAssetRef(path);

            if (assetRef != null)
            {
                Log.Resource.I("LoadAsync {0} in Cache", name);
                return(assetRef.Refrence());
            }

            if (string.IsNullOrEmpty(assetBundlePath))
            {
                assetBundlePath = Core.Path.instance.Resolve(path, TYPE.AssetBundle);
            }
            var assetBundleRef = await LoadAssetBundleAsync(assetBundlePath, option);

            if (assetBundleRef == null)
            {
                return(null);
            }

            var assetBundle        = assetBundleRef.Get <AssetBundle>();
            var assetBundleRequest = assetBundle.LoadAssetAsync(name);
            var result             = await Loading.instance.Wrap(async() =>
            {
                return(await HookProgress(assetBundleRequest, option.progress, 0.7f));
            }, option);

            if (!result)
            {
                return(null);
            }

            var asset = assetBundleRequest.asset;

            if (asset == null)
            {
                return(null);
            }

            assetRef = new AssetRef(path, asset, new List <AssetRef>()
            {
                assetBundleRef
            });
            CacheAssetRef(assetRef.Refrence());
            return(assetRef);
        }
Example #4
0
 public async Task <T> Run <T>(Func <Task <T> > asynFunc, LoadingOption option)
 {
     try
     {
         if (option.block)
         {
             Show();
         }
         return(await RunInner(asynFunc));
     }
     finally
     {
         if (option.block)
         {
             Hide();
         }
     }
 }
Example #5
0
        public async Task <AsyncOperation> LoadSceneAsync(string path, LoadingOption option)
        {
            path = Core.Path.instance.Resolve(path, TYPE.Scene);
            var operation = SceneManager.LoadSceneAsync(path);

            operation.allowSceneActivation = option.allowSceneActivation;
            var result = await Loading.instance.Wrap(async() =>
            {
                return(await HookProgress(operation, option.progress));
            }, option);

            if (!result)
            {
                return(null);
            }

            return(operation);
        }
Example #6
0
        public async Task <T> Wrap <T>(Func <Task <T> > asynFunc, LoadingOption option)
        {
            Func <Task <T> > WrapInner = async() =>
            {
                try
                {
                    var ret = await asynFunc();

                    return(ret);
                }
                catch (Exception e)
                {
                    Log.Framework.Error(e);
                    throw new LoadingTimeoutError();
                }
            };

            return(await Run <T>(WrapInner, option));
        }
Example #7
0
        protected virtual async Task <AssetBundleManifest> LoadAssetBundleManifest()
        {
            var option      = new LoadingOption();
            var path        = $"Assets/{Path.AssetBundleFolder}/{Path.AssetBundleFolder}";
            var assetBundle = await LoadAssetBundleSingleAsync(path, option);

            var assetBundleRef = new AssetRef(path, assetBundle);

            var name     = "AssetBundleManifest";
            var manifest = await assetBundle.LoadAssetAsync <AssetBundleManifest>(name);

            var manifestRef = new AssetRef(name, manifest, new List <AssetRef>()
            {
                assetBundleRef
            });

            CacheAssetRef(manifestRef.Refrence());
            return(manifest as AssetBundleManifest);
        }
Example #8
0
 public async Task <AsyncOperation> Load(string name, LoadingOption option)
 {
     option.allowSceneActivation = false;
     return(await Resource.instance.LoadSceneAsync(name, option));
 }
Example #9
0
        protected virtual async Task <AssetBundle> LoadAssetBundleSingleAsync(string path, LoadingOption option, float weight = 1.0f)
        {
            Log.Resource.Exception(new NotImplementedException());
            await Observable.TimerFrame(1);

            return(null);
        }
Example #10
0
        protected async Task <AssetRef> LoadAssetBundleAndDepencenciesAsync(string path, LoadingOption option, Dictionary <string, bool> wait = null)
        {
            wait = wait ?? new Dictionary <string, bool>();
            if (wait.ContainsKey(path))
            {
                return(null);
            }

            wait[path] = true;
            var dependencies = assetBundleManifest.GetAllDependencies(path);

            foreach (var dependence in dependencies)
            {
                await LoadAssetBundleAndDepencenciesAsync(dependence, option, wait);
            }

            var assetBundle = await LoadAssetBundleSingleAsync(path, option);

            var dependenceRefs = dependencies.Select(x => FindAssetRef(x)).ToList();
            var assetBundleRef = new AssetRef(path, assetBundle, dependenceRefs);

            CacheAssetRef(assetBundleRef);
            return(assetBundleRef);
        }
Example #11
0
 public async Task <AssetRef> LoadAsync(string path, LoadingOption option, TYPE type = TYPE.Prefab)
 {
     return(await LoadAsync(path, type, option, ""));
 }