/// <summary>
        /// 创建对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="panelName"></param>
        /// <param name="onCreate"></param>
        public void CreatePanel(UIInfoBase itemInfo, UnityEngine.Events.UnityAction <GameObject> onCreate)
        {
            if (_cansaleKeys.Contains(itemInfo.panelName))
            {
                _cansaleKeys.RemoveAll(x => x == itemInfo.panelName);
            }

            if (!_loadingKeys.Contains(itemInfo.IDName))
            {
                _loadingKeys.Add(itemInfo.IDName);
                var bInfo = itemInfo as BundleUIInfo;
                var pInfo = itemInfo as PrefabUIInfo;
                var rInfo = itemInfo as ResourceUIInfo;

                if (pInfo != null)
                {
                    var go = GetGameObjectInfo(pInfo);
                    if (onCreate != null)
                    {
                        onCreate.Invoke(go);
                    }
                }
                else if (rInfo != null)
                {
                    var go = GetGameObjectInfo(rInfo);
                    if (onCreate != null)
                    {
                        onCreate.Invoke(go);
                    }
                }
                else if (bInfo != null)
                {
                    if (bundleLoader != null)
                    {
                        bundleLoader.LoadAssetAsync <GameObject>(bInfo.bundleName, bInfo.panelName, (x) => {
                            if (x != null)
                            {
                                var instence = CreateInstance(x, bInfo);
                                if (onCreate != null)
                                {
                                    onCreate.Invoke(instence);
                                }
                                _loadingKeys.Remove(bInfo.IDName);
                            }
                        });
                    }
                    else
                    {
                        Debug.LogError("请先设置AssetBundle加载时的规则!");
                    }
                }
            }
        }
示例#2
0
        IEnumerator DownLoadAssetBundleByBuffer(string url, UnityEngine.Events.UnityAction <byte[]> cb, UnityEngine.Events.UnityAction onFailed)
        {
            using (UnityWebRequest www = UnityWebRequest.Get(url))
            {
                DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
                www.downloadHandler = handler;
                yield return(www.Send());

                if (www.isError)
                {
                    LoggerManager.Instance().LogErrorFormat("DownLoadAssetBundleByBuffer Failed:{0} url={1}", www.error, url);

                    if (null != onFailed)
                    {
                        onFailed.Invoke();
                    }
                }
                else
                {
                    LoggerManager.Instance().LogFormat("DownLoadAssetBundleByBuffer Succeed : Length = {0} ...", handler.data.Length);

                    if (null != cb)
                    {
                        cb.Invoke(www.downloadHandler.data);
                    }
                }
            }
        }