Пример #1
0
        /// <summary>
        /// 获取各种类型的Asset
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="assetName"></param>
        /// <param name="action"></param>
        public void LoadAsset <T>(string assetName, Action <T> action) where T : UnityEngine.Object
        {
            T      obj        = default(T);
            string bundleName = BundleManager.GetBundleNameByAsset(assetName);

#if UNITY_EDITOR
            if (BundleManager.usedAssetBundle)
            {
                // 编辑器需要标记好资产,才能使用该API
                string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(bundleName, assetName);
                if (assetPaths.Length == 0)
                {
                    Log.Error("There is no asset with name \"" + assetName + "\" in " + assetName);
                }
                else
                {
                    UnityEngine.Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]);
                    obj = AssetDatabase.LoadAssetAtPath <T>(assetPaths[0]);
                    action.Invoke(obj);
                }
            }
            else
#endif
            {
                GetLoadedBundle(bundleName, (ab) => {
                    if (ab == null)
                    {
                        return;
                    }

                    T asset = ab.LoadAsset <T>(assetName);
                    action.Invoke(asset);
                });
            }
        }
Пример #2
0
        /// <summary>
        /// 获取AssetBundle
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <param name="action"></param>
        public void GetLoadedBundle(string assetBundleName, Action <AssetBundle> action)
        {
            string      error = string.Empty;
            AssetBundle ab    = BundleManager.GetLoadedBundle(assetBundleName, out error);

            if (ab == null)
            {
                Log.Info(error);
                Runtime.CoroutineHelper.Instance.StartCoroutine(BundleManager.StartDownloadBundle(assetBundleName, action));
            }
            else
            {
                action.Invoke(ab);
            }
        }
Пример #3
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns></returns>
        public IEnumerator Initialize()
        {
            IEnumerator e = BundleManager.Initialize();

            while (e.MoveNext())
            {
                yield return(null);
            }

            e = BundleManager.PreDownloadInitBundle();
            while (e.MoveNext())
            {
                yield return(null);
            }
        }
Пример #4
0
        /// <summary>
        /// 利用协成开始下载AssetBundle
        /// </summary>
        /// <returns></returns>
        public static IEnumerator StartDownloadBundle(string bundleName, Action <AssetBundle> back)
        {
            while (m_IsMultiDownloading)
            {
                yield return(null);
            }

            AddMultiDownloadBundleQueue(bundleName);
            IEnumerator e = StartMultiDownloadBundle();

            while (e.MoveNext())
            {
                yield return(null);
            }

            string      error = string.Empty;
            AssetBundle ab    = BundleManager.GetLoadedBundle(bundleName, out error);

            if (ab == null)
            {
                Log.Info(error);
            }
            back.Invoke(ab);
        }
Пример #5
0
 /// <summary>
 /// 获取下载进度
 /// </summary>
 /// <returns></returns>
 public float GetDownloadProgress()
 {
     return(BundleManager.GetDownloadProgress());
 }
Пример #6
0
 /// <summary>
 /// 设置资源服务器地址
 /// </summary>
 /// <param name="url"></param>
 public void SetBundleBaseURL(string url)
 {
     BundleManager.SetBundleBaseURL(url);
 }
Пример #7
0
 /// <summary>
 /// 卸载资源。
 /// </summary>
 /// <param name="asset">要卸载的资源。</param>
 public void UnloadBundle(string bundle)
 {
     BundleManager.UnloadAssetBundle(bundle);
 }