Exemplo n.º 1
0
    protected override void DoBundleLoadHandler(string _BundleKey, AssetBundles.LoadedAssetBundle _Bundle, string [] pathArray)
    {
        Debug.Log("DoBundleLoadHandler() " + _BundleKey);

        if (true == m_Checks.ContainsKey(_BundleKey))
        {
            m_Checks[_BundleKey].m_CurrentState = CheckState.CheckComplete;
        }

        this.State = ProgressState.Checking;
    }
Exemplo n.º 2
0
    protected virtual IEnumerator LoadAssetFromExistBundle_Delegate(AssetBundles.LoadedAssetBundle _LoadedBundle
                                                                    , string _AssetName)
    {
        var request = _LoadedBundle.m_AssetBundle.LoadAssetAsync <UnityEngine.Object>(_AssetName);

        yield return(request);

        // Get the asset.
        var assetObject = request.asset;

        assetLoadHandler(assetObject);
    }
Exemplo n.º 3
0
    protected virtual IEnumerator LoadAssetFromExistBundle_Callback(AssetBundles.LoadedAssetBundle _LoadedBundle
                                                                    , string assetName
                                                                    , System.Action <UnityEngine.Object> _CallbackFunc)
    {
        // Load asset from assetBundle.
        var request = _LoadedBundle.m_AssetBundle.LoadAssetAsync <UnityEngine.Object>(assetName);

        yield return(request);

        // Get the asset.
        var assetObject = request.asset;

        _CallbackFunc(assetObject);
    }
Exemplo n.º 4
0
    protected override void DoBundleLoadHandler(string _BundleKey, AssetBundles.LoadedAssetBundle _Bundle, string [] pathArray)
    {
        if (null == _Bundle)
        {
                        #if UNITY_EDITOR
            if (!AssetBundles.AssetBundleManager.SimulateAssetBundleInEditor)
            {
                Debug.LogError("DoBundleLoadHandler() Fatal Error, Bundle missed");
            }
                        #else
            Debug.LogError("DoBundleLoadHandler() Fatal Error, Bundle missed");
                        #endif
        }

        Debug.Log("DoBundleLoadHandler=" + _BundleKey);

        if (true == m_Checks.ContainsKey(_BundleKey))
        {
            m_Checks[_BundleKey].m_CurrentState = CheckState.CheckComplete;
        }

        // check unload
        ABSetupInfo setupData = null;
        m_BundleInfos.TryGetValue(_BundleKey, out setupData);

        if (null == setupData)
        {
            Debug.Log("DoBundleLoadHandler() null == setting _Bundle.m_BundleKey=" + _BundleKey);
        }
        else
        {
            if (setupData.ReleaseTiming == ABReleaseTiming.LoadByDemand.ToString() ||
                setupData.ReleaseTiming == ABReleaseTiming.KeepUnload.ToString()
                )
            {
                Debug.Log("DoBundleLoadHandler() UnloadAssetBundle=" + _BundleKey);
                AssetBundles.AssetBundleManager.UnloadAssetBundle(_BundleKey);
            }
        }

        this.State = ProgressState.Checking;
    }
        protected override void FinishDownload()
        {
            AssetBundle bundle = m_Operation.assetBundle;

            if (bundle == null)
            {
                error = string.Format("failed to load assetBundle {0}.", assetBundleName);
                return;
            }

            if (bundle == null)
            {
                error = string.Format("{0} is not a valid asset bundle.", assetBundleName);
            }
            else
            {
                assetBundle = new LoadedAssetBundle(bundle);
            }
            m_Operation = null;
        }
        public override bool Update()
        {
            if (m_Request != null)
            {
                return(false);
            }

            LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

            if (bundle != null)
            {
                m_Request = SceneManager.LoadSceneAsync(m_LevelName, m_IsAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single);

                return(false);
            }
            else
            {
                return(true);
            }
        }
        // Returns true if more Update calls are required.
        public override bool Update()
        {
            if (m_Request != null)
            {
                return(false);
            }

            LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

            if (bundle != null)
            {
                ///@TODO: When asset bundle download fails this throws an exception...
                m_Request = bundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type);
                return(false);
            }
            else
            {
                return(true);
            }
        }
        /// <summary>
        /// Retrieves an asset bundle that has previously been requested via LoadAssetBundle.
        /// Returns null if the asset bundle or one of its dependencies have not been downloaded yet.
        /// </summary>
        static public LoadedAssetBundle GetLoadedAssetBundle(string assetBundleName, out string error)
        {
            if (m_DownloadingErrors.TryGetValue(assetBundleName, out error))
            {
                return(null);
            }

            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle == null)
            {
                return(null);
            }

            // No dependencies are recorded, only the bundle itself is required.
            string[] dependencies = null;
            if (!m_Dependencies.TryGetValue(assetBundleName, out dependencies))
            {
                return(bundle);
            }

            // Make sure all dependencies are loaded
            foreach (var dependency in dependencies)
            {
                if (m_DownloadingErrors.TryGetValue(dependency, out error))
                {
                    return(null);
                }

                // Wait all the dependent assetBundles being loaded.
                LoadedAssetBundle dependentBundle;
                m_LoadedAssetBundles.TryGetValue(dependency, out dependentBundle);
                if (dependentBundle == null)
                {
                    return(null);
                }
            }

            return(bundle);
        }
Exemplo n.º 9
0
        static protected void UnloadAssetBundleInternal(string assetBundleName)
        {
            string            error;
            LoadedAssetBundle bundle = GetLoadedAssetBundle(assetBundleName, out error);

            if (bundle == null)
            {
                return;
            }

            if (--bundle.m_ReferencedCount == 0)
            {
                bundle.m_AssetBundle.Unload(true);
                m_LoadedAssetBundles.Remove(assetBundleName);

                if (Debug.developerConsoleVisible)
                {
                    Log(LogType.Info, assetBundleName + " has been unloaded successfully");
                }
            }
        }
        // Returns true if more Update calls are required.
        public override bool Update(UrlAssetBundleLoadCtrl loadCtrl)
        {
            if (m_Request != null)
            {
                return(false);
            }

            LoadedAssetBundle bundle = loadCtrl.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

            if (bundle != null)
            {
                ///@TODO: When asset bundle download fails this throws an exception...
                m_Request = bundle.m_AssetBundle.LoadAllAssetsAsync(m_Type);
                return(false);
            }
            else
            {
                progress = loadCtrl.GetProgress(m_AssetBundleName);
                return(true);
            }
        }
        protected override void FinishDownload()
        {
            error = m_WebRequest.error;
            if (!string.IsNullOrEmpty(error))
            {
                return;
            }

            AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(m_WebRequest);

            if (bundle == null)
            {
                error = string.Format("{0} is not a valid asset bundle.", assetBundleName);
            }
            else
            {
                assetBundle = new LoadedAssetBundle(bundle);
            }

            m_WebRequest.Dispose();
            m_WebRequest = null;
        }
Exemplo n.º 12
0
        protected override void FinishDownload()
        {
            error = m_WWW.error;
            if (!string.IsNullOrEmpty(error))
            {
                return;
            }

            AssetBundle bundle = m_WWW.assetBundle;

            if (bundle == null)
            {
                error = string.Format("{0} is not a valid asset bundle.", assetBundleName);
            }
            else
            {
                assetBundle = new LoadedAssetBundle(m_WWW.assetBundle);
            }

            m_WWW.Dispose();
            m_WWW = null;
        }
Exemplo n.º 13
0
        public override bool Update()
        {
            if (this.m_Request != null)
            {
                return(false);
            }
            LoadedAssetBundle loadedAssetBundle = AssetBundleManager.GetLoadedAssetBundle(this.m_AssetBundleName, out this.m_DownloadingError);

            if (loadedAssetBundle != null)
            {
                if (this.m_IsAdditive)
                {
                    this.m_Request = Application.LoadLevelAdditiveAsync(this.m_LevelName);
                }
                else
                {
                    this.m_Request = Application.LoadLevelAsync(this.m_LevelName);
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 14
0
        // Where we actuall call WWW to download the assetBundle.
        static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest)
        {
            // Already loaded.
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
            // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
            if (m_DownloadingWWWs.ContainsKey(assetBundleName))
            {
                return(true);
            }

            WWW    download = null;
            string url      = m_BaseDownloadingURL + assetBundleName;

            //Debug.Log ("Downloading " + assetBundleName + ", isLoadingAssetBundleManifest: " + isLoadingAssetBundleManifest);

            // For manifest assetbundle, always download it as we don't have hash for it.
            if (isLoadingAssetBundleManifest)
            {
                download = new WWW(url);
            }
            else
            {
                download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
            }
//			Debug.LogError("Add download file from Url: " + url);
            m_DownloadingWWWs.Add(assetBundleName, download);

            return(false);
        }
Exemplo n.º 15
0
        // Returns true if more Update calls are required.
        public override bool Update()
        {
            if (m_Request != null)
            {
                return(false);
            }

            LoadedAssetBundle bundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

            if (bundle != null)
            {
                ///@TODO: When asset bundle download fails this throws an exception...
                m_Request = bundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type);
                // 默认为true,表示一旦场景加载完毕即刻切换场景,设置为false后不自动切换场景,在需要切换场景时,设置m_Request.allowSceneActivation = true;
                // m_Request.allowSceneActivation = false;
                // m_Request.progress 为下载进度
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 16
0
        // Where we actuall call WWW to download the assetBundle.
        static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest)
        {
            // Already loaded.
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
            // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
            if (m_DownloadingWWWs.ContainsKey(assetBundleName))
            {
                return(true);
            }

            UnityWebRequest download = null;
            string          url      = m_BaseDownloadingURL + assetBundleName;

            if (isLoadingAssetBundleManifest)
            {
                download = UnityWebRequestAssetBundle.GetAssetBundle(url);// new UnityWebRequest(url);
            }
            //else
            //	download =  WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);

            if (download != null)
            {
                m_DownloadingWWWs.Add(assetBundleName, download);
            }

            return(false);
        }
Exemplo n.º 17
0
        protected override void FinishDownload()
        {
            error = m_request.error;
            if (!string.IsNullOrEmpty(error))
            {
                return;
            }

            var         handler = m_request.downloadHandler as DownloadHandlerAssetBundle;
            AssetBundle bundle  = handler.assetBundle;

            if (bundle == null)
            {
                error = string.Format("{0} is not a valid asset bundle.", assetBundleName);
            }
            else
            {
                assetBundle = new LoadedAssetBundle(bundle);
            }

            m_request.Dispose();
            m_request   = null;
            m_Operation = null;
        }
        public bool LoadAssetBundleInternal(string assetBundleName, System.Action _completeDownloadCallBack)
        {
            // Already loaded.
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            LoadingAssetBundle _loadingBundle = null;

            m_LoadingAssetBundles.TryGetValue(assetBundleName, out _loadingBundle);
            if (_loadingBundle != null)
            {
                if (_completeDownloadCallBack != null)
                {
                    _loadingBundle.m_Action_Complete_Download += _completeDownloadCallBack;
                }
                return(true);
            }

            _loadingBundle = new LoadingAssetBundle(assetBundleName);
            if (_completeDownloadCallBack != null)
            {
                _loadingBundle.m_Action_Complete_Download += _completeDownloadCallBack;
            }
            m_LoadingAssetBundles.Add(assetBundleName, _loadingBundle);
            string url = m_BaseDownloadingURL + assetBundleName;

            _loadingBundle.m_DownloadingWWW = WWW.LoadFromCacheOrDownload(url, 1);

            return(false);
        }
        // Sets up download operation for the given asset bundle if it's not downloaded already.
        static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest)
        {
            // Already loaded.
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
            // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
            if (m_DownloadingBundles.Contains(assetBundleName))
            {
                return(true);
            }

            string bundleBaseDownloadingURL = GetAssetBundleBaseDownloadingURL(assetBundleName);

            if (bundleBaseDownloadingURL.ToLower().StartsWith("odr://"))
            {
#if ENABLE_IOS_ON_DEMAND_RESOURCES
                Log(LogType.Info, "Requesting bundle " + assetBundleName + " through ODR");
                m_InProgressOperations.Add(new AssetBundleDownloadFromODROperation(assetBundleName));
#else
                new ApplicationException("Can't load bundle " + assetBundleName + " through ODR: this Unity version or build target doesn't support it.");
#endif
            }
            else if (bundleBaseDownloadingURL.ToLower().StartsWith("res://"))
            {
#if ENABLE_IOS_APP_SLICING
                Log(LogType.Info, "Requesting bundle " + assetBundleName + " through asset catalog");
                m_InProgressOperations.Add(new AssetBundleOpenFromAssetCatalogOperation(assetBundleName));
#else
                new ApplicationException("Can't load bundle " + assetBundleName + " through asset catalog: this Unity version or build target doesn't support it.");
#endif
            }
            else
            {
                WWW download = null;

                if (!bundleBaseDownloadingURL.EndsWith("/"))
                {
                    bundleBaseDownloadingURL += "/";
                }

                string url = bundleBaseDownloadingURL + assetBundleName;

                // For manifest assetbundle, always download it as we don't have hash for it.
                if (isLoadingAssetBundleManifest)
                {
                    download = new WWW(url);
                }
                else
                {
                    download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
                }

                m_InProgressOperations.Add(new AssetBundleDownloadFromWebOperation(assetBundleName, download));
            }
            m_DownloadingBundles.Add(assetBundleName);

            return(false);
        }
Exemplo n.º 20
0
 protected virtual void DoBundleLoadHandler(string _BundleKey, AssetBundles.LoadedAssetBundle _Bundle, string [] pathArray)
 {
     // UnityEngine.Debug.Log("DoBundleLoadHandler() _BundleKey=" + _BundleKey ) ;
 }
Exemplo n.º 21
0
        // Where we actuall call WWW to download the assetBundle.
        static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest)
        {
#if ENABLE_NDINFRA_DEBUG_INFO
            AssetBundleManager.Log(LogType.Info, "LoadAssetBundleInternal assetBundleName=" + assetBundleName);
#endif// ENABLE_NDINFRA_DEBUG_INFO

            // Already loaded.
            LoadedAssetBundle bundle = null;

#if ENABLE_NDINFRA_CUSTOM
            // assetBundleName may be with variant extention, but m_LoadedAssetBundles doesn't
            string shortKey = RemovePostVariant(assetBundleName);
            m_LoadedAssetBundles.TryGetValue(shortKey, out bundle);
#else
            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
#endif // ENABLE_NDINFRA_CUSTOM

            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
            // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
            if (m_DownloadingWWWs.ContainsKey(assetBundleName))
            {
                return(true);
            }

            WWW    download = null;
            string url      = m_BaseDownloadingURL + assetBundleName;

#if ENABLE_NDINFRA_CUSTOM
            // start check version
            // assetBundleName is with variant extension.

#if ENABLE_NDINFRA_DEBUG_INFO
            Debug.LogWarning("LoadAssetBundleInternal input and assemble url=" + url);
#endif // ENABLE_NDINFRA_DEBUG_INFO

            string keyWoVariant = RemovePostVariant(assetBundleName);

            bool isVersionExist = m_VersionTable.ContainsKey(keyWoVariant);
            int  targetVersion  = 0;
            if (isVersionExist)
            {
                targetVersion = m_VersionTable[keyWoVariant];
            }


            // check if we need to use local asset bundle
            bool isLocalExist     = m_LocalBundleTable.ContainsKey(keyWoVariant);
            bool isUseLocalBundle = isLocalExist &&
                                    (!isVersionExist || (isVersionExist &&
                                                         m_LocalBundleTable[keyWoVariant] >= m_VersionTable[keyWoVariant]));

            if (true == isUseLocalBundle)
            {
                targetVersion  = m_LocalBundleTable[keyWoVariant];
                isVersionExist = true;
                // change path to streaming assets path
                url = GetStreamingAssetsPath() + "/AssetBundles/" + Utility.GetPlatformName() + "/" + assetBundleName;
#if ENABLE_NDINFRA_DEBUG_INFO
                AssetBundleManager.Log(LogType.Info, "LoadAssetBundleInternal local bundle url=" + url);
#endif // ENABLE_NDINFRA_DEBUG_INFO
            }

            if (m_EnableVersionCheck && isVersionExist)
            {
                // url was used here
                download = WWW.LoadFromCacheOrDownload(url, targetVersion);
            }
            else
            {
#if ENABLE_NDINFRA_DEBUG_INFO
                AssetBundleManager.Log(LogType.Info, "LoadAssetBundleInternal version not exists, beware of caching.");
#endif // ENABLE_NDINFRA_DEBUG_INFO
#endif // ENABLE_NDINFRA_CUSTOM

            // For manifest assetbundle, always download it as we don't have hash for it.
            if (isLoadingAssetBundleManifest)
            {
                download = new WWW(url);
            }
            else
            {
                download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
            }

#if ENABLE_NDINFRA_CUSTOM
        }
#endif  // ENABLE_NDINFRA_CUSTOM


            m_DownloadingWWWs.Add(assetBundleName, download);

            return(false);
        }
Exemplo n.º 22
0
        // Sets up download operation for the given asset bundle if it's not downloaded already.
        static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest)
        {
            // Already loaded.
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
            // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
            if (m_DownloadingBundles.Contains(assetBundleName))
            {
                return(true);
            }

            string bundleBaseDownloadingURL = GetAssetBundleBaseDownloadingURL(assetBundleName);

            if (bundleBaseDownloadingURL.ToLower().StartsWith("odr://"))
            {
#if ENABLE_IOS_ON_DEMAND_RESOURCES
                Log(LogType.Info, "Requesting bundle " + assetBundleName + " through ODR");
                m_InProgressOperations.Add(new AssetBundleDownloadFromODROperation(assetBundleName));
#else
                new ApplicationException("Can't load bundle " + assetBundleName + " through ODR: this Unity version or build target doesn't support it.");
#endif
            }
            else if (bundleBaseDownloadingURL.ToLower().StartsWith("res://"))
            {
#if ENABLE_IOS_APP_SLICING
                Log(LogType.Info, "Requesting bundle " + assetBundleName + " through asset catalog");
                m_InProgressOperations.Add(new AssetBundleOpenFromAssetCatalogOperation(assetBundleName));
#else
                new ApplicationException("Can't load bundle " + assetBundleName + " through asset catalog: this Unity version or build target doesn't support it.");
#endif
            }
            else
            {
                if (!bundleBaseDownloadingURL.EndsWith("/"))
                {
                    bundleBaseDownloadingURL += "/";
                }

                string url = bundleBaseDownloadingURL + assetBundleName;

                if (IsAssetBundleEncrypted)
                {
#if ABM_USE_UWREQ
                    UnityWebRequest request = UnityWebRequest.Get(url);
                    m_InProgressOperations.Add(new AssetBundleDownloadWebRequestFromEncryptOperation(assetBundleName, request));
#else
                    WWW download = new WWW(url);
                    m_InProgressOperations.Add(new AssetBundleDownloadFromWebOperation(assetBundleName, download));
#endif
                }
                else
                {
#if ABM_USE_UWREQ
                    // If url refers to a file in StreamingAssets, use AssetBundle.LoadFromFileAsync to load.
                    // UnityWebRequest also is able to load from there, but we use the former API because:
                    // - UnityWebRequest under Android OS fails to load StreamingAssets files (at least Unity5.50 or less)
                    // - or UnityWebRequest anyway internally calls AssetBundle.LoadFromFileAsync for StreamingAssets files
                    if (url.StartsWith(Application.streamingAssetsPath))
                    {
                        m_InProgressOperations.Add(new AssetBundleDownloadFileOperation(assetBundleName, url));
                    }
                    else
                    {
                        UnityWebRequest request = null;

                        if (isLoadingAssetBundleManifest || url.ToLower().StartsWith("file://"))
                        {
                            // For manifest assetbundle, always download it as we don't have hash for it.
                            request = UnityWebRequest.GetAssetBundle(url);
                        }
                        else
                        {
                            request = UnityWebRequest.GetAssetBundle(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
                        }
                        m_InProgressOperations.Add(new AssetBundleDownloadWebRequestOperation(assetBundleName, request));
                    }
#else
                    WWW download = null;
                    if (isLoadingAssetBundleManifest || url.ToLower().StartsWith("file://"))
                    {
                        // For manifest assetbundle, always download it as we don't have hash for it.
                        download = new WWW(url);
                    }
                    else
                    {
                        download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
                    }
                    m_InProgressOperations.Add(new AssetBundleDownloadFromWebOperation(assetBundleName, download));
#endif
                }
            }
            m_DownloadingBundles.Add(assetBundleName);

            return(false);
        }
        public IEnumerator LoadAssetBundleAsync(string assetBundleName)
        {
            assetBundleName = assetBundleName.ToLower();

            AssetBundleCreateRequest bundleRequest = AssetBundle.LoadFromFileAsync(AssetBundleName2FilePath(assetBundleName));
            yield return bundleRequest;
            if (bundleRequest.assetBundle == null)
            {
                Debug.LogErrorFormat("Load AssetBundle Failed: {0}", assetBundleName);
                yield break;
            }
            LoadedAssetBundle loadedAssetBundle = new LoadedAssetBundle(bundleRequest.assetBundle);
            mLoadedAssetBundles.Add(assetBundleName, loadedAssetBundle);
        }
        public void LoadAssetBundle(string assetBundleName)
        {
            assetBundleName = assetBundleName.ToLower();

            AssetBundle asssetBundle = AssetBundle.LoadFromFile(AssetBundleName2FilePath(assetBundleName));
            if (asssetBundle == null)
            {
                Debug.LogErrorFormat("Load AssetBundle Failed: {0}", assetBundleName);
                return;
            }
            LoadedAssetBundle loadedAssetBundle = new LoadedAssetBundle(asssetBundle);
            mLoadedAssetBundles.Add(assetBundleName, loadedAssetBundle);
        }
Exemplo n.º 25
0
        // Where we actuall call WWW to download the assetBundle.
        //这里我们事实调用WWW下载assetBundle
        static protected bool LoadAssetBundleInternal(string assetBundleName, bool isLoadingAssetBundleManifest)
        {
            Debug.Log("load asset:" + assetBundleName);


            // Already loaded.
            //已经加载过;
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // In the demo, we never have duplicate WWWs as we wait LoadAssetAsync()/LoadLevelAsync() to be finished before calling another LoadAssetAsync()/LoadLevelAsync().
            // But in the real case, users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.

            //我们需要考虑www的引用计数?;
            //在这个demo,我们从来没有重复WWWs ,我们等LoadAssetAsync()/LoadLevelAsync()完成之前,调用其他LoadAssetAsync()/LoadLevelAsync();
            //但实际情况,用户可能调用LoadAssetAsync()/LoadLevelAsync()几次,然后等待它们完成这可能有重复的www。

            if (m_DownloadingWWWs.ContainsKey(assetBundleName))
            {
                return(true);
            }

            WWW download = null;

            string url = "";



#if UNITY_STANDALONE_WIN || UNITY_EDITOR
            url = m_BaseDownloadingURL + "\\" + assetBundleName; //自定义语句;
#elif UNITY_ANDROID || UNITY_IOS
            url = m_BaseDownloadingURL + "/" + assetBundleName;  //自定义语句;
#endif

            // For manifest assetbundle, always download it as we don't have hash for it.
            //因为 manifest assetbundle,已经下载它所以我们不对它hash;


            if (isLoadingAssetBundleManifest)
            {
                download = new WWW(url);
            }
            else
            {
                download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleManifest.GetAssetBundleHash(assetBundleName), 0);
            }


            m_DownloadingWWWs.Add(assetBundleName, download);

            Debug.Log("download 资源: " + url);

            return(false);
        }