Пример #1
0
        /// <summary>
        /// 载入AssetBundle
        /// </summary>
        /// <param name="abName"></param>
        /// <returns></returns>
        AssetBundle LoadAssetBundle(string abName)
        {
            if (!abName.EndsWith(AppConst.ExtName))
            {
                abName += AppConst.ExtName;
            }
            AssetBundleInfo bundleInfo = GetLoadedAssetBundle(abName);

            if (bundleInfo == null)
            {
                string uri = Util.DataPath + abName;
                Debug.LogWarning("LoadFile::>> " + uri);

                AssetBundle bundle = AssetBundle.LoadFromFile(uri); //关联数据的素材绑定
                bundleInfo = new AssetBundleInfo(bundle);
                m_LoadedAssetBundles.Add(abName, bundleInfo);
            }
            else
            {
                bundleInfo.m_ReferencedCount++;
            }
            return(bundleInfo.m_AssetBundle);
        }
Пример #2
0
        IEnumerator OnLoadAsset(string abName, Type assetType)
        {
            AssetBundleInfo bundleInfo = GetLoadedAssetBundle(abName);

            if (bundleInfo == null)
            {
                yield return(mResMgr.StartCoroutine(OnLoadAssetBundle(abName, assetType)));

                bundleInfo = GetLoadedAssetBundle(abName);
                if (bundleInfo == null)
                {
                    m_LoadRequests.Remove(abName);
                    Debug.LogError("OnLoadAsset--->>>" + abName);
                    yield break;
                }
            }
            List <LoadAssetRequest> list = null;

            if (!m_LoadRequests.TryGetValue(abName, out list))
            {
                m_LoadRequests.Remove(abName);
                yield break;
            }
            for (int i = 0; i < list.Count; i++)
            {
                string[]       assetNames = list[i].assetNames;
                List <UObject> result     = new List <UObject>();

                AssetBundle ab = bundleInfo.m_AssetBundle;
                if (assetNames != null)
                {
                    for (int j = 0; j < assetNames.Length; j++)
                    {
                        string assetPath = assetNames[j];
                        var    request   = ab.LoadAssetAsync(assetPath, assetType);
                        yield return(request);

                        result.Add(request.asset);
                    }
                }
                else
                {
                    var request = ab.LoadAllAssetsAsync();
                    yield return(request);

                    result = new List <UObject>(request.allAssets);
                }
                if (list[i].sharpFunc != null)
                {
                    list[i].sharpFunc(result.ToArray());
                    list[i].sharpFunc = null;
                }
                if (list[i].luaFunc != null)
                {
                    list[i].luaFunc.Call((object)result.ToArray());
                    list[i].luaFunc.Dispose();
                    list[i].luaFunc = null;
                }
                bundleInfo.m_ReferencedCount++;
            }
            m_LoadRequests.Remove(abName);
        }