Exemple #1
0
        /// <summary>
        /// 卸载已经加载的ab
        /// </summary>
        public void UnloadAssetBundle(string abName, bool remoteAll)
        {
            com.QH.QPGame.GameUtils.Logger.Res.Log("unload ab:" + abName);

#if !UNITY_EDITOR || TEST_AB
            abName += GameHelper.GetABExt(Application.platform);
            GetLoader(abName).UnloadAssetBundle(abName, remoteAll);
#endif
        }
Exemple #2
0
        public T GetLoadedAsset <T>(string ab, string asset) where T : UnityEngine.Object
        {
            string abName = ab + GameHelper.GetABExt(Application.platform);
            var    obj    = GetLoader(abName).GetAsset <T>(abName, asset);

            if (obj != default(T))
            {
                return(obj);
                //return Instantiate<T>(obj);
            }
            return(default(T));
        }
Exemple #3
0
        public bool IsAssetBundleCached(string abName)
        {
            if (!Caching.ready || !Caching.enabled)
            {
                return(false);
            }
            abName += GameHelper.GetABExt(Application.platform);
            if (!localResConfig.ContainsKey(abName))
            {
                com.QH.QPGame.GameUtils.Logger.Res.Log("no match config for bundle which named:" + abName);
                return(false);
            }

            int    version = int.Parse(localResConfig[abName].Version);
            string url     = GetLoader(abName).URI + abName;

            return(Caching.IsVersionCached(url, version));
        }
Exemple #4
0
        /// <summary>
        /// 从文件系统中异步加载ab
        /// </summary>
        /// <param name="abName"></param>
        /// <returns></returns>
        public IEnumerator LoadAssetBundleAync(string abName)
        {
            com.QH.QPGame.GameUtils.Logger.Res.Log("try to load bundle. Name:" + abName);

            float beginReadTime = Time.realtimeSinceStartup;

            abName += GameHelper.GetABExt(Application.platform);
            if (!localResConfig.ContainsKey(abName))
            {
                com.QH.QPGame.GameUtils.Logger.Res.LogError("no match config for bundle which named:" + abName);
                yield break;
            }

            int version = int.Parse(localResConfig[abName].Version);

            yield return(StartCoroutine(GetLoader(abName).LoadAssetBundleAsync(abName, version)));

            float useTime = Time.realtimeSinceStartup - beginReadTime;

            com.QH.QPGame.GameUtils.Logger.Res.Log("ab loaded. Name:" + abName + " UseTime:" + useTime);
        }
Exemple #5
0
        /// <summary>
        /// 从已经加载的ab包中同步读取asset
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="abName"></param>
        /// <param name="asset"></param>
        /// <returns></returns>
        public T LoadAsset <T>(string abName, string asset) where T : UnityEngine.Object
        {
            T t = default(T);

#if UNITY_EDITOR && !TEST_AB
            //编辑器状态下从文件系统中读取
            abName += GameHelper.GetABExt(UnityEditor.EditorUserBuildSettings.activeBuildTarget);
            string[] paths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(abName, asset);
            foreach (var path in paths)
            {
                com.QH.QPGame.GameUtils.Logger.Res.Log("load asset from path! AB:" + abName + "  Asset:" + asset + " Path:" + path);
                t = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(path);
                if (t != default(T))
                {
                    break;
                }
            }

            if (t == default(T))
            {
                t = Resources.Load <T>(asset);
            }
#else
            abName += GameHelper.GetABExt(Application.platform);
            t       = GetLoader(abName).GetAsset <T>(abName, asset);
            if (t != default(T))
            {
                return(t);
            }
#endif

            if (t == default(T))
            {
                com.QH.QPGame.GameUtils.Logger.Sys.LogError("load asset from ab failed! AB:" + abName + "  Asset:" + asset);
            }

            return(t);
        }
Exemple #6
0
 /// <summary>
 /// 返回是否加载了某个ab包
 /// </summary>
 public bool IsAssetBundleLoaded(string abName)
 {
     abName += GameHelper.GetABExt(Application.platform);
     return(GetLoader(abName).GetAssetBundle(abName) != null);
 }
Exemple #7
0
        public IEnumerator LoadAssetAsync <T>(string ab, string asset) where T : UnityEngine.Object
        {
            string abName = ab + GameHelper.GetABExt(Application.platform);

            yield return(StartCoroutine(GetLoader(abName).LoadAssetAsync <T>(abName, asset)));
        }