Example #1
0
        private async Task LoadAllAssests(string assetBundleName, AssetBundle assetBundle)
        {
            if (!Define.isUseAssetBundle)
            {
#if UNITY_EDITOR
                var realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    string             path      = $"{assetBundleName}/{assetName}".ToLower();
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    ABManager.resourceCache[path] = resource;
                }
#endif
                return;
            }
            if (assetBundle == null)
            {
                ZLog.Error($"{assetBundleName} is Null?");
                return;
            }
            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create <AssetsLoaderAsync, AssetBundle>(assetBundle))
                {
                    assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                }
                foreach (UnityEngine.Object asset in assets)
                {
                    string path = $"{assetBundleName}/{asset.name}".ToLower();
                    ABManager.resourceCache[path] = asset;
                }
            }
        }
Example #2
0
        public async Task LoadOneBundleAsync(string assetBundleName)
        {
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                return;
            }

            //Log.Debug($"---------------load one bundle {assetBundleName}");
            if (!Define.IsAsync)
            {
                string[] realPath = null;
#if UNITY_EDITOR
                realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    AddResource(assetBundleName, assetName, resource);
                }

                this.bundles[assetBundleName] = new ABInfo(assetBundleName, null);
#endif
                return;
            }

            string      p           = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
            AssetBundle assetBundle = null;
            if (!File.Exists(p))
            {
                p = Path.Combine(PathHelper.AppResPath, assetBundleName);
            }

            using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = ComponentFactory.Create <AssetsBundleLoaderAsync>())
            {
                assetBundle = await assetsBundleLoaderAsync.LoadAsync(p);
            }

            if (assetBundle == null)
            {
                throw new Exception($"assets bundle not found: {assetBundleName}");
            }

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create <AssetsLoaderAsync, AssetBundle>(assetBundle))
                {
                    assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                }
                foreach (UnityEngine.Object asset in assets)
                {
                    AddResource(assetBundleName, asset.name, asset);
                }
            }

            this.bundles[assetBundleName] = new ABInfo(assetBundleName, assetBundle);
        }
Example #3
0
        public async Task LoadOneBundleAsync(string assetBundleName)
        {
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                return;
            }


            if (this.cacheDictionary.ContainsKey(assetBundleName))
            {
                abInfo = this.cacheDictionary[assetBundleName];
                ++abInfo.RefCount;
                this.bundles[assetBundleName] = abInfo;
                this.cacheDictionary.Remove(assetBundleName);
                return;
            }


            if (!Define.IsAsync)
            {
#if UNITY_EDITOR
                string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    string             path      = $"{assetBundleName}/{assetName}".ToLower();
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    this.resourceCache[path] = resource;
                }

                this.bundles[assetBundleName] = new ABInfo(assetBundleName, null);
                return;
#endif
            }

            AssetBundle assetBundle;
            using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = ComponentFactory.Create <AssetsBundleLoaderAsync>())
            {
                assetBundle = await assetsBundleLoaderAsync.LoadAsync(assetBundleName);
            }

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create <AssetsLoaderAsync, AssetBundle>(assetBundle))
                {
                    assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                }
                foreach (UnityEngine.Object asset in assets)
                {
                    string path = $"{assetBundleName}/{asset.name}".ToLower();
                    this.resourceCache[path] = asset;
                }
            }

            this.bundles[assetBundleName] = new ABInfo(assetBundleName, assetBundle);
        }
Example #4
0
        public async Task LoadOneBundleAsync(string assetBundleName, Action <float> updateProgress = null)
        {
            //Log.Debug($"---------------load one bundle {assetBundleName}");
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                //Log.Debug($"读取到已经有的Bundle: {assetBundleName}");
                ++abInfo.RefCount;
                return;
            }


            if (this.cacheDictionary.ContainsKey(assetBundleName))
            {
                abInfo = this.cacheDictionary[assetBundleName];
                ++abInfo.RefCount;
                this.bundles[assetBundleName] = abInfo;
                this.cacheDictionary.Remove(assetBundleName);
                return;
            }


            if (!Define.isUseAssetBundle)
            {
#if UNITY_EDITOR
                //ZLog.Info("UNITY_EDITOR LoadOneBundleAsync");
                //string[] realPath = null;
                //realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                //foreach (string s in realPath)
                //{
                //	string assetName = Path.GetFileNameWithoutExtension(s);
                //	string path = $"{assetBundleName}/{assetName}".ToLower();
                //	UnityEngine.Object resource = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(s);
                //	this.resourceCache[path] = resource;
                //}

                this.bundles[assetBundleName] = new ABInfo(assetBundleName, null);
#endif
                return;
            }

            string      p           = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
            AssetBundle assetBundle = null;
            if (!File.Exists(p))
            {
                p = Path.Combine(PathHelper.AppResPath, assetBundleName);
            }

            using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = ComponentFactory.Create <AssetsBundleLoaderAsync>())
            {
                assetBundle = await assetsBundleLoaderAsync.LoadAsync(p, updateProgress);
            }

            if (assetBundle == null)
            {
                throw new Exception($"assets bundle not found: {p}");
            }
            if (!assetBundle.isStreamedSceneAssetBundle && assetBundleName == "StreamingAssets")
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = ComponentFactory.Create <AssetsLoaderAsync, AssetBundle>(assetBundle))
                {
                    assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                }
                foreach (UnityEngine.Object asset in assets)
                {
                    string path = $"{assetBundleName}/{asset.name}".ToLower();
                    ABManager.resourceCache[path] = asset;
                }
            }

            this.bundles[assetBundleName] = new ABInfo(assetBundleName, assetBundle);
        }