Exemplo n.º 1
0
        internal static BundleRequest LoadBundle(string assetBundleName, bool asyncMode)
        {
            if (string.IsNullOrEmpty(assetBundleName))
            {
                Debug.LogError("assetBundleName == null");
                return(null);
            }

            assetBundleName = RemapVariantName(assetBundleName);
            var url = GetDataPath(assetBundleName) + assetBundleName;

            BundleRequest bundle;

            if (_bundles.TryGetValue(url, out bundle))
            {
                if (!bundle.isDone && !asyncMode)
                {
                    var assetBundle = bundle.assetBundle;
                    Debug.LogWarning("Bundle is loading:" + assetBundle.name);
                }
                bundle.Retain();
                return(bundle);
            }

            if (url.StartsWith("http://", StringComparison.Ordinal) ||
                url.StartsWith("https://", StringComparison.Ordinal) ||
                url.StartsWith("file://", StringComparison.Ordinal) ||
                url.StartsWith("ftp://", StringComparison.Ordinal))
            {
                bundle = new WebBundleRequest();
            }
            else
            {
                bundle = asyncMode ? new BundleAsyncRequest() : new BundleRequest();
            }

            bundle.url = url;
            _bundles.Add(url, bundle);

            if (MAX_BUNDLES_PERFRAME > 0 && (bundle is BundleAsyncRequest || bundle is WebBundleRequest))
            {
                _toloadBundles.Add(bundle);
            }
            else
            {
                bundle.Load();
                _loadingBundles.Add(bundle);
                Log("LoadBundle: " + url);
            }

            LoadDependencies(bundle, assetBundleName, asyncMode);

            bundle.Retain();
            return(bundle);
        }
Exemplo n.º 2
0
        internal static BundleRequest LoadBundle(string assetBundleName, bool asyncMode)
        {
            if (string.IsNullOrEmpty(assetBundleName))
            {
                Debug.LogError("bundle == null");
                return(null);
            }

            assetBundleName = RemapVariantName(assetBundleName);
            var url = GetDataPath(assetBundleName) + assetBundleName;

            BundleRequest bundle;

            if (BundleRequests.TryGetValue(assetBundleName, out bundle))
            {
                bundle.Retain();
                if (!bundle.isDone && !asyncMode)
                {
                    bundle.LoadImmediate();
                }

                return(bundle);
            }

            if (url.StartsWith("http://", StringComparison.Ordinal) ||
                url.StartsWith("https://", StringComparison.Ordinal) ||
                url.StartsWith("file://", StringComparison.Ordinal) ||
                url.StartsWith("ftp://", StringComparison.Ordinal))
            {
                bundle = new WebBundleRequest();
            }
            else
            {
                bundle = asyncMode ? new BundleAsyncRequest() : new BundleRequest();
            }

            bundle.url  = url;
            bundle.name = assetBundleName;

            BundleRequests.Add(assetBundleName, bundle);

            if (MAX_BUNDLES_PERFRAME > 0 && (bundle is BundleAsyncRequest || bundle is WebBundleRequest))
            {
                ToloadBundles.Add(bundle);
            }
            else
            {
                bundle.Load();
                LoadingBundles.Add(bundle);
                LogFormat("LoadBundle: {0}", url);
            }

            bundle.Retain();
            return(bundle);
        }
Exemplo n.º 3
0
        internal static BundleRequest LoadBundle(string assetBundleName, bool isLoadingAssetBundleManifest, bool asyncMode)
        {
            if (string.IsNullOrEmpty(assetBundleName))
            {
                Debug.LogError("assetBundleName == null");
                return(null);
            }

            if (!isLoadingAssetBundleManifest)
            {
                if (bundleManifest == null)
                {
                    Debug.LogError("Please initialize AssetBundleManifest by calling Bundles.Initialize()");
                    return(null);
                }

                assetBundleName = RemapVariantName(assetBundleName);
            }

            var url = GetDataPath(assetBundleName) + assetBundleName;

            BundleRequest bundle;

            if (_bundles.TryGetValue(url, out bundle))
            {
                bundle.Retain();
                return(bundle);
            }

            if (url.StartsWith("http://", StringComparison.Ordinal) ||
                url.StartsWith("https://", StringComparison.Ordinal) ||
                url.StartsWith("file://", StringComparison.Ordinal) ||
                url.StartsWith("ftp://", StringComparison.Ordinal))
            {
                bundle = new WebBundleRequest
                {
                    hash                         = bundleManifest != null?bundleManifest.GetAssetBundleHash(assetBundleName) : new Hash128(),
                                           cache = !isLoadingAssetBundleManifest
                }
            }
            ;
            else
            {
                bundle = asyncMode ? new BundleAsyncRequest() : new BundleRequest();
            }

            bundle.url = url;

            _bundles.Add(url, bundle);

            _bundleRequests.Add(bundle);

            if (MAX_BUNDLE_LOAD_SIZE_PERFREME > 0 && (bundle is BundleAsyncRequest || bundle is WebBundleRequest))
            {
                _bundles2Load.Add(bundle);
            }
            else
            {
                bundle.Load();
                Log("LoadBundle: " + url);
            }

            if (!isLoadingAssetBundleManifest)
            {
                LoadDependencies(bundle, assetBundleName, asyncMode);
            }

            bundle.Retain();
            return(bundle);
        }