コード例 #1
0
        /// <summary>
        /// 非框架托管式资源包加载
        /// </summary>
        /// <param name="assetBundleName">资源包名称。</param>
        /// <param name="fileUri">资源包文件路径。</param>
        /// <param name="loadAssetBundleCallback">加载回调函数。</param>
        /// <returns></returns>
        private IEnumerator LoadAssetBundleCo(string assetBundleName, string fileUri, LoadAssetBundleCallbacks loadAssetBundleCallbacks, object userData)
        {
            WWW www = new WWW(fileUri);

            yield return(www);

            AssetBundle assetBundle  = www.assetBundle;
            string      errorMessage = www.error;

            www.Dispose();

            if (loadAssetBundleCallbacks != null)
            {
                if (string.IsNullOrEmpty(errorMessage) && assetBundle != null)
                {
                    m_LoadedAssetBundleDic.Add(assetBundleName, assetBundle);
                    if (loadAssetBundleCallbacks.LoadAssetBundleSuccessCallback != null)
                    {
                        loadAssetBundleCallbacks.LoadAssetBundleSuccessCallback(assetBundleName, assetBundle, 0, userData);
                    }
                }
                else
                {
                    if (loadAssetBundleCallbacks.LoadAssetBundleFailureCallback != null)
                    {
                        loadAssetBundleCallbacks.LoadAssetBundleFailureCallback(assetBundleName, LoadResourceStatus.NotExist, errorMessage, userData);
                    }
                }
            }
            m_LoadingAssetList.Remove(assetBundleName);
        }
 public override void OnLoadAssetSuccess(LoadResourceAgent agent, object asset, float duration)
 {
     base.OnLoadAssetSuccess(agent, asset, duration);
     if (m_LoadAssetBundleCallbacks.LoadAssetBundleSuccessCallback != null)
     {
         m_LoadAssetBundleCallbacks.LoadAssetBundleSuccessCallback(AssetBundleName, asset, duration, UserData);
     }
 }
コード例 #3
0
        /// <summary>
        /// 异步加载资源包
        /// </summary>
        /// <param name="assetBundleName">要加载的资源包的名称。</param>
        /// <param name="loadAssetBundleCallbacks">加载回调函数。</param>
        /// <param name="userData">自定义数据。</param>
        public void LoadAssetBundle(string assetBundleName, LoadAssetBundleCallbacks loadAssetBundleCallbacks, object userData)
        {
            if (IsLoadResourceReady)
            {
                m_ResourceManager.LoadAssetBundle(assetBundleName, loadAssetBundleCallbacks, userData);
            }
            else
            {
                if (m_LoadedAssetBundleDic.ContainsKey(assetBundleName))
                {
                    if (loadAssetBundleCallbacks != null)
                    {
                        if (loadAssetBundleCallbacks.LoadAssetBundleSuccessCallback != null)
                        {
                            loadAssetBundleCallbacks.LoadAssetBundleSuccessCallback(assetBundleName, GetAssetBundle(assetBundleName), 0, userData);
                        }
                    }
                    return;
                }

                if (m_LoadingAssetList.ContainsKey(assetBundleName))
                {
                    return;
                }

                m_LoadingAssetList.Add(assetBundleName, loadAssetBundleCallbacks);
                string filePath = Utility.Path.GetCombinePath(m_ResourceManager.ReadWritePath, Utility.Path.GetResourceNameWithSuffix(assetBundleName));

                if (File.Exists(filePath))
                {
                    filePath = Utility.Path.GetRemotePath(m_ResourceManager.ReadWritePath, Utility.Path.GetResourceNameWithSuffix(assetBundleName));
                }
                else
                {
                    filePath = Utility.Path.GetRemotePath(m_ResourceManager.ReadOnlyPath, Utility.Path.GetResourceNameWithSuffix(assetBundleName));
                }

                StartCoroutine(LoadAssetBundleCo(assetBundleName, filePath, loadAssetBundleCallbacks, userData));
            }
        }