示例#1
0
        /// <summary>
        /// 读取配置
        /// </summary>
        /// <param name="data"></param>
        /// <param name="offset"></param>
        public void Read(byte[] data, ref int offset)
        {
            _cachedAssetInfos.Clear();
            _cachedAssetInfoMap.Clear();

            if (data == null)
            {
                return;
            }

            int dataLength = data.Length - offset;

            if (dataLength < 6)
            {
                return;
            }

            int storedDataLength = MemoryOperator.ReadInt(data, ref offset);

            if (storedDataLength < 6 || storedDataLength > dataLength)
            {
                return;
            }
            //
            int version = MemoryOperator.ReadShort(data, ref offset);

            if (version != Version)
            {
                return;
            }
            //信息数量
            int amount = MemoryOperator.ReadShort(data, ref offset);

            for (int i = 0; i < amount; i++)
            {
                NetAssetInfo info = new NetAssetInfo();
                info.Key       = MemoryOperator.ReadString(data, ref offset);
                info.AssetType = (NetAssetType)MemoryOperator.ReadShort(data, ref offset);
                if (info.AssetType == NetAssetType.Image)
                {
                    info.ImageWidth  = MemoryOperator.ReadShort(data, ref offset);
                    info.ImageHeight = MemoryOperator.ReadShort(data, ref offset);
                }
                //
                info.LastModifyTime = MemoryOperator.ReadDateTime(data, ref offset);
                //
                if (!_cachedAssetInfoMap.ContainsKey(info.Key))
                {
                    _cachedAssetInfoMap.Add(info.Key, info);
                    _cachedAssetInfos.Add(info);
                }
            }
            //排序
            _cachedAssetInfos.Sort();
        }
        /// <summary>
        /// 添加UI事件回调
        /// </summary>
        /// <param name="list">UI事件</param>
        /// <param name="id">回调ID</param>
        /// <param name="oneShot">是否回调一次</param>
        public void AddUIEventHandle(UnityEvent list, int id, bool oneShot)
        {
            if (list == null || id <= 0)
            {
                return;
            }
            EventData data;

            if (!_eventDataCache.Pop(out data))
            {
                data = new EventData();
            }
            data.Create(OnUIEventCSCall, list, id, oneShot);
            _eventData.Add(data);
        }
        /// <summary>
        /// 加载常驻bundle
        /// </summary>
        /// <param name="complete"></param>
        /// <param name="progress"></param>
        /// <returns></returns>
        public IEnumerator LoadResidentBundles(Action complete = null, BundleBatchLoadingDelegate progress = null)
        {
            ResPackConfig config = ResService.GetInstance().PackConfig;

            if (config == null)
            {
                JW.Common.Log.LogE("In LoadResidentBundles(), but ResPackConfig is null.");

                if (complete != null)
                {
                    complete();
                }

                yield break;
            }

            JWObjList <BundlePackInfo> bundleList = new JWObjList <BundlePackInfo>();

            for (int i = 0; i < config.PackInfo.Count; i++)
            {
                BundlePackInfo p = config.PackInfo[i] as BundlePackInfo;
                if (p != null && p.Life == EBundleLife.Resident)
                {
                    bundleList.Add(p);
                }
            }

            yield return(StartCoroutine(BundleService.GetInstance().BatchLoadAsync(bundleList, complete, progress)));
        }
示例#4
0
        /// 初始化
        public void Initialize()
        {
            if (_isInitialized)
            {
                return;
            }
            //记录默认显示的优先级
            _defaultShowPriority = ShowPriority;
            _isInitialized       = true;
            //初始化UI组件
            UIComponent[] ccs   = new UIComponent[100];
            int           ccCnt = 0;

            UIUtility.GetComponentsInChildren <UIComponent>(gameObject, ccs, ref ccCnt);
            if (ccs != null && ccCnt > 0)
            {
                if (_uiComponents == null)
                {
                    _uiComponents = new JWObjList <UIComponent>();
                }
                for (int i = 0; i < ccCnt; i++)
                {
                    ccs[i].Initialize(this);
                    //Cache
                    _uiComponents.Add(ccs[i]);
                }
            }
        }
 public static void Recycle(DeferUnloadData data)
 {
     if (data != null)
     {
         data.Reset();
         _pool.Add(data);
     }
 }
示例#6
0
        //同步
        public void Update(float fCurrentTime)
        {
            m_kAudioTempList.Clear();

            for (int i = m_kAudioList.Count - 1; i >= 0; i--)
            {
                Audio audio = m_kAudioList[i];
                if (audio.IsFadeOutEnd)
                {
                    audio.Stop();
                    m_kAudioList.RemoveAt(i);
                    continue;
                }
                else
                {
                    if ((!audio.IsLoop) && (audio.EndTime < fCurrentTime))
                    {
                        audio.Stop();
                        m_kAudioList.RemoveAt(i);
                        continue;
                    }
                    else
                    {
                        m_kAudioTempList.Add(audio);
                    }
                }
            }

            m_kAudioList.Clear();
            //
            for (int i = 0; i < m_kAudioTempList.Count; i++)
            {
                Audio audio2 = m_kAudioTempList[i];
                m_kAudioList.Add(audio2);
            }

            for (int i = 0; i < m_kAudioList.Count; i++)
            {
                Audio audio3 = m_kAudioList[i];
                audio3.Update(fCurrentTime);
            }
        }
        /// <summary>
        /// 根据资源列表取bundle列表
        /// </summary>
        /// <param name="resourceList"></param>
        /// <param name="recordResources"></param>
        public JWObjList <BundlePackInfo> GetBundlePackInfoListForResources(JWObjList <string> resourceList, bool recordResources)
        {
            if (resourceList == null || resourceList.Count == 0)
            {
                return(null);
            }

            ResPackConfig config = ResService.GetInstance().PackConfig;

            if (config == null)
            {
                if (recordResources)
                {
                    _unbundledResources.AddRange(resourceList);
                }

                return(null);
            }

            JWObjList <BundlePackInfo> bundleList = null;

            for (int i = 0; i < resourceList.Count; i++)
            {
                string         path = resourceList[i];
                BundlePackInfo info = config.GetPackInfoForResource(JW.Res.FileUtil.EraseExtension(path)) as BundlePackInfo;
                if (info != null)
                {
                    if (bundleList == null)
                    {
                        bundleList = new JWObjList <BundlePackInfo>();
                    }

                    if (!bundleList.Contains(info))
                    {
                        bundleList.Add(info);
                    }

                    // bundle正在加载中的资源
                    if (recordResources && !_loadingResources.Contains(path))
                    {
                        _loadingResources.Add(path);
                    }
                }
                else
                {
                    if (recordResources && !_unbundledResources.Contains(path))
                    {
                        _unbundledResources.Add(path);
                    }
                }
            }

            return(bundleList);
        }
示例#8
0
        /// <summary>
        /// 回收
        /// </summary>
        /// <param name="r"></param>
        public static void Recycle(ResObj r)
        {
            if (r != null)
            {
                r.Reset(null);

                if (!_pool.Contains(r))
                {
                    _pool.Add(r);
                }
            }
        }
示例#9
0
 /// <summary>
 /// 显示或者关闭菊花
 /// </summary>
 /// <param name="key">键</param>
 /// <param name="isShow">是否显示</param>
 public void ShowWaiting(string key, bool isShow, string tip = "")
 {
     if (isShow)
     {
         if (_waitingKeyList.Contains(key))
         {
             //JW.Common.Log.LogE("ShowWaiting Logic Error Repeat Key:" + key);
             if (_waiting != null)
             {
                 _waiting.ShowTip(tip);
             }
             return;
         }
         _waitingKeyList.Add(key);
         if (_waiting == null)
         {
             _waiting = UIFormHelper.CreateResidentFormClass <UIWaiting>();
             _waiting.ShowTip(tip);
         }
         else
         {
             _waiting.ActiveForm(true);
             _waiting.ShowTip(tip);
         }
     }
     else
     {
         int firstIndex = _waitingKeyList.IndexOf(key);
         if (firstIndex >= 0 && firstIndex < _waitingKeyList.Count)
         {
             _waitingKeyList.RemoveAt(firstIndex);
         }
         if (_waitingKeyList.Count == 0)
         {
             if (null != _waiting)
             {
                 _waiting.ActiveForm(false);
                 //UIFormHelper.DisposeFormClass<UIWaiting>(ref _waiting);
                 //_waiting = null;
             }
         }
     }
 }
        /// <summary>
        /// 获取预加载bundle列表
        /// </summary>
        /// <returns></returns>
        public JWObjList <string> GetPreloadBundles()
        {
            JWObjList <string> bundleList = new JWObjList <string>();

            ResPackConfig config = ResService.GetInstance().PackConfig;

            for (int i = 0; i < config.PackInfo.Count; i++)
            {
                BundlePackInfo p = config.PackInfo[i] as BundlePackInfo;
                if (p == null)
                {
                    continue;
                }

                if (p.HasFlag(EBundleFlag.PreLoad))
                {
                    bundleList.Add(p.Path);
                }
            }

            return(bundleList);
        }
        /// <summary>
        /// 获取已加载的bundle对应的资源
        /// </summary>
        /// <param name="bundlePath"></param>
        /// <returns></returns>
        public JWObjList <string> GetLoadedBundleResources(string bundlePath)
        {
            if (string.IsNullOrEmpty(bundlePath) || _loadingResources.Count == 0)
            {
                return(null);
            }

            ResPackConfig config = ResService.GetInstance().PackConfig;

            if (config == null)
            {
                return(null);
            }

            BundlePackInfo pi = config.GetPackInfo(bundlePath) as BundlePackInfo;

            if (pi == null)
            {
                return(null);
            }

            for (int i = _loadingResources.Count - 1; i >= 0; i--)
            {
                string path = _loadingResources[i];
                if (pi.Contains(path))
                {
                    if (!_relatedResources.Contains(path))
                    {
                        _relatedResources.Add(path);
                    }

                    _loadingResources.Remove(path);
                }
            }

            return(_relatedResources);
        }
        /// <summary>
        /// 加载状态相关bundle
        /// </summary>
        /// <param name="resourceList">资源路径列表</param>
        /// <param name="complete">加载完成回调</param>
        /// <param name="progress">加载进度回调</param>
        /// <param name="loaded">单个bundle加载完成回调</param>
        /// <param name="singleSync">true:当只有一个bundle时,使用同步加载;否则使用并发异步加载</param>
        /// <returns></returns>
        public IEnumerator LoadBundle(JWObjList <string> resourceList, Action complete = null, BundleBatchLoadingDelegate progress = null, BundleLoadedOneDelegate loaded = null, bool singleSync = true)
        {
            bool record = loaded != null;

            // 剔除已有资源
            for (int i = 0; i < resourceList.Count;)
            {
                string path = resourceList[i];
                if (ResService.GetInstance().Exists(path))
                {
                    if (record)
                    {
                        _unbundledResources.Add(path);
                    }

                    resourceList.RemoveAt(i);
                    continue;
                }

                i++;
            }

            // bundle list
            JWObjList <BundlePackInfo> bundleList = GetBundlePackInfoListForResources(resourceList, record);

            // 异步返回,在处理完源数据之后避免resourceList被reset
            yield return(null);

            // 未打包资源
            if (_unbundledResources.Count > 0)
            {
                if (loaded != null)
                {
                    loaded(_unbundledResources, true);
                }

                _unbundledResources.Clear();
            }

            // load
            if (bundleList != null && bundleList.Count > 0)
            {
                if (singleSync && bundleList.Count == 1)
                {
                    // 只有一个bundle,使用同步加载方式
                    BundleService.GetInstance().LoadSync(bundleList[0]);

                    if (progress != null)
                    {
                        progress(1f);
                    }

                    if (loaded != null)
                    {
                        AssetBundle        bundle           = BundleService.GetInstance().GetBundle(bundleList[0].Path);
                        JWObjList <string> relatedResources = GetLoadedBundleResources(bundleList[0].Path);
                        if (relatedResources != null && relatedResources.Count > 0)
                        {
                            loaded(relatedResources, bundle != null);
                            relatedResources.Clear();
                        }

                        BundleService.GetInstance().Unload(bundleList[0]);
                    }

                    if (complete != null)
                    {
                        complete();
                    }
                }
                else
                {
                    // 多个bundle,使用并发加载
                    yield return(StartCoroutine(BundleService.GetInstance().BatchLoadAsync(bundleList, delegate()
                    {
                        if (complete != null)
                        {
                            complete();
                        }
                    }, progress, delegate(BundleRef bundle)
                    {
                        if (bundle != null)
                        {
                            if (loaded != null)
                            {
                                JWObjList <string> relatedResources = GetLoadedBundleResources(bundle.Path);
                                if (relatedResources != null && relatedResources.Count > 0)
                                {
                                    loaded(relatedResources, true);
                                    relatedResources.Clear();
                                }

                                BundleService.GetInstance().Unload(bundle.PackInfo);
                            }
                        }
                    }, delegate(BundlePackInfo pi, string error)
                    {
                        if (loaded != null)
                        {
                            JWObjList <string> relatedResources = GetLoadedBundleResources(pi.Path);
                            if (relatedResources != null && relatedResources.Count > 0)
                            {
                                //bool succ = (pi.IsNoBundle());

                                //loaded(relatedResources, succ);
                                //relatedResources.Clear();
                            }
                        }
                    })));
                }
            }
            else
            {
                if (complete != null)
                {
                    complete();
                }
            }
        }
示例#13
0
        private IEnumerator AsynchronousLoad_LoadAssetBundle(JWObjList <string> stringList, JWArrayList <AssetData> assetDataList)
        {
            while (true)
            {
                stringList.Clear();
                assetDataList.Clear();
                for (int i = 0; i < _data.Count;)
                {
                    AssetData data = _data[i];
                    if (data.Priority != _loadAssetBundlePriority)
                    {
                        ++i;
                        continue;
                    }

                    _data.RemoveAt(i);

                    if (_assetManager.GetCacheCount(data.Name) >= data.Count)
                    {
                        if (data.Callback != null)
                        {
                            assetDataList.Add(data);
                        }
                        continue;
                    }

                    LoadData loadData;
                    loadData.Data            = data;
                    loadData.LoadBundleState = LoadStateLoading;
                    loadData.Request         = null;

                    bool insert = false;
                    for (int j = _resourceRequesting.Count - 1; j >= 0; --j)
                    {
                        if (_resourceRequesting[j].Data.Priority <= data.Priority)
                        {
                            _resourceRequesting.Insert(j + 1, loadData);
                            insert = true;
                            break;
                        }
                    }

                    if (!insert)
                    {
                        _resourceRequesting.Insert(0, loadData);
                    }

                    stringList.Add(data.Filename);

                    if (_loadAssetBundlePriority >= LoadPriority.Preprocess)
                    {
                        break;
                    }
                }

                yield return(null);

                if (stringList.Count > 0)
                {
#if USE_PACK_RES
                    BundleMediator.GetInstance().LoadBundle(stringList, OnBundleLoadCompleted);
#else
                    OnBundleLoadCompleted(stringList, true);
#endif
                }

                yield return(null);

                for (int i = 0; i < assetDataList.Count; i++)
                {
                    AssetData data = assetDataList[i];
                    if (data.Callback != null)
                    {
                        data.Callback.OnLoadAssetCompleted(data.Name, AssetLoadResult.Success, null);
                        yield return(null);
                    }
                }

                yield return(InstructionEnd);
            }
        }
示例#14
0
        /// <summary>
        /// 打开窗口
        /// </summary>
        /// <param name="formCpt">窗口组件</param>
        /// <returns></returns>
        public UIForm OpenForm(UIForm formCpt, bool useCamera = true)
        {
            if (formCpt == null)
            {
                JW.Common.Log.LogE("Open Form Error Null Arg");
                return(null);
            }
            UIForm old;

            //检查同名Form是否存在
            old = GetUnClosedForm(formCpt.FormPath);
            //只有一个 重新打开
            if (old != null && old.IsSingleton)
            {
                //更新sequence
                old.Open(_formSequence, _formOpenOrder, true);
                _formSequence++;
                _formOpenOrder++;
                _needSortForms = true;
                //
                return(old);
            }
            //
            GameObject formGo = formCpt.gameObject;

            if (formGo == null)
            {
                JW.Common.Log.LogE("Form " + formCpt.FormPath + " Open Fail!!!");
                return(null);
            }

            //确保form为active
            if (!formGo.activeSelf)
            {
                formGo.ExtSetActive(true);
            }
            //
            //挂接
            if (formGo.transform.parent != _uiRoot.transform)
            {
                formGo.transform.SetParent(_uiRoot.transform);
            }

            //设置参数
            if (formCpt != null)
            {
                formCpt.Open(useCamera ? _formCamera : null, _formSequence, _formOpenOrder, false);
                //close 同组Form
                if (formCpt.GroupId > 0)
                {
                    CloseGroupForm(formCpt.GroupId);
                }
                //监听
                formCpt.EventHandler += this.OnUIFormEvent;
                _forms.Add(formCpt);
            }
            _formSequence++;
            _formOpenOrder++;
            _needSortForms = true;
            return(formCpt);
        }