Example #1
0
        /// <summary>
        /// 获取AssetBundle资源
        /// </summary>
        /// <param name="pathkey">路径key</param>
        /// <returns></returns>
        public AssetBundle GetAssetBundle(string pathkey)
        {
            BundleCache bc = null;

            if (!mAssetBundleDic.TryGetValue(pathkey, out bc))
            {
                return(null);
            }
            return(bc.assetBundle);
        }
Example #2
0
        /// <summary>
        /// 加载AssetBundle中的资源
        /// </summary>
        /// <param name="ab">AssetBundle对象</param>
        /// <param name="sourcename">资源名</param>
        /// <param name="cb">回调</param>
        /// <returns></returns>
        //IEnumerator LoadSourceEnumerator(AssetBundle ab, string sourcename, UnityAction<UnityEngine.Object> cb)
        //{
        //    AssetBundleRequest abr = ab.LoadAssetAsync(sourcename);
        //    Debug.Log("Source AssetBundleRequest");
        //    yield return abr;
        //    if (abr.isDone)
        //    {
        //        if (abr.asset != null)
        //        {
        //            Debug.Log("Source cb");
        //            cb(abr.asset);
        //        }
        //        else
        //        {
        //            DebugMod.LogError("Can't find res " + sourcename + "in assetbundle");
        //        }
        //    }
        //}


        /// <summary>
        /// 加载AssetBundle
        /// </summary>
        /// <param name="path">资源路径</param>
        /// <param name="sourcename">资源名</param>
        /// <param name="cb">回调</param>
        /// <returns></returns>
        //IEnumerator LoadBundleEnumerator(string path, string sourcename, UnityAction<Object> cb, bool forceloadAsyn = false)
        //{
        //    using (WWW www = new WWW(path))
        //    {
        //        yield return www;
        //        if (www.isDone)
        //        {
        //            if (mAssetBundleDic.ContainsKey(path))
        //            {
        //                LoadAsset(path, sourcename, cb, forceloadAsyn);
        //                yield break;
        //            }

        //            AssetBundle ab = www.assetBundle;
        //            if (null == ab)
        //            {
        //                DebugMod.LogError("www.assetBundle is null when load:" + path);
        //                yield break;
        //            }

        //            AddAssetBundle(path, ab);
        //            LoadAsset(path, sourcename, cb, forceloadAsyn);
        //        }
        //        else
        //        {
        //            DebugMod.LogError(www.error);
        //        }
        //    }
        //}

        /// <summary>
        /// 加载AssetBundle
        /// </summary>
        /// <param name="path">资源路径</param>
        /// <param name="sourcename">资源名</param>
        /// <param name="cb">回调</param>
        /// <returns></returns>
        //IEnumerator LoadBundleEnumerator(string path, UnityAction<AssetBundle> cb, bool managercharge = true)
        //{
        //    using (WWW www = new WWW(path))
        //    {
        //        yield return www;
        //        if (www.isDone)
        //        {
        //            AssetBundle ab = www.assetBundle;
        //            if (null == ab)
        //            {
        //                DebugMod.LogError("www.assetBundle is null when load:" + path);
        //                yield break;
        //            }
        //            if (managercharge)
        //            {
        //                AddAssetBundle(path, ab);
        //                LoadAsset(path, cb);
        //            }
        //            else
        //            {
        //                try
        //                {
        //                    cb(ab);
        //                }
        //                catch
        //                {
        //                    DebugMod.LogError("Error occored in LoadBundleEnumerator callback delegate");
        //                }
        //            }

        //        }
        //        else
        //        {
        //            DebugMod.LogError(www.error);
        //        }
        //    }
        //}


        /// <summary>
        /// 添加AssetBundle资源到字典
        /// </summary>
        /// <param name="key">路径key</param>
        /// <param name="assetBundle">bundle资源</param>
        /// <returns></returns>
        public void AddAssetBundle(string pathkey, AssetBundle assetBundle)
        {
            mAssetBundleDic[pathkey] = new BundleCache(assetBundle);
        }