示例#1
0
        public override IEnumerator LoadResource(IInfoData iData, LoadBundleFinish delFinish, object param1, object param2)
        {
            ModelInfoData infoData = iData as ModelInfoData;

            if (infoData == null)
            {
                yield break;
            }

#if UNITY_EDITOR
            if (PlayerSetting.SimulateAssetBundleInEditor)
            {
                if (null != delFinish)
                {
                    string     assetPath = GetBundleLoadUrl(PathModelPrefab, infoData.name.ToLower(), ".prefab");
                    GameObject gb        = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);
                    delFinish(infoData, gb, param1, param2);
                }

                yield break;
            }
#endif

            ///这里充当加载标识的作用,表示如果当前已经在加载这个资源了,则等待直到资源加载完成
            while (m_dicSingleBundleRef.Contains(infoData.GetBundleName()))
            {
                yield return(0);
            }

            ///添加对应的引用计数
            if (!m_dicSingleBundleRef.Contains(infoData.GetBundleName()))
            {
                m_dicSingleBundleRef.Add(infoData.GetBundleName());
            }

            if (LoadFromCache(infoData, delFinish, param1, param2))
            {
                yield break;
            }

            string assetBundleName = infoData.name.ToLower();

            string loadPath = GetBundleLoadUrl(PathModelPrefab, assetBundleName, m_bundleExt);

            AssetBundleCreateRequest req = GetBundleRequest(loadPath);
            yield return(req);

            yield return(ProcessLoad(req.assetBundle, infoData, delFinish, param1, param2));
        }
示例#2
0
        private static bool LoadFromCache(ModelInfoData infoData, LoadBundleFinish delFinish, object param1, object param2)
        {
            string assetBundleName = infoData.GetBundleName();

            if (m_dicSingleBundleCache.ContainsKey(assetBundleName))
            {
                ///添加对应的引用计数
                //  if (!m_dicSingleBundleRef.Contains(assetBundleName))
                {
                    //     m_dicSingleBundleRef.Add(assetBundleName);
                }

                GameObject modelObject = m_dicSingleBundleCache[assetBundleName].modelOrEffect;

                if (null != delFinish)
                {
                    delFinish(infoData, modelObject, param1, param2);
                }

                return(true);
            }
            return(false);
        }
示例#3
0
        private static IEnumerator ProcessLoad(AssetBundle bundle, ModelInfoData infoData,
                                               LoadBundleFinish delFinish, object param1, object param2, bool isAync = true)
        {
            if (null == bundle)
            {
                yield break;
            }

            AssetBundleRequest req = bundle.LoadAssetAsync(infoData.GetBundleName(), typeof(GameObject));

            yield return(req);

            if (m_dicSingleBundleRef.Contains(infoData.GetBundleName()))
            {
                m_dicSingleBundleRef.Remove(infoData.GetBundleName());
            }

            GameObject retObj = req.asset as GameObject;

            if (null != delFinish)
            {
                delFinish(infoData, retObj, param1, param2);
            }
        }