Пример #1
0
        private IEnumerator CoLoadUI(UIInfo info, Action <UIBase> showEvent = null, params object[] userDatas)
        {
            LoadUIData data = PrePushToAllStack(info, userDatas);
            //先从对象池里面加载物体,没有找到对应的物体就加载一个,加载出来要放进对象池中保存起来
            GameObject obj = PoolManager.instance.GetObject <GameObject>(info.loadPath, info.loadPath.GetAssetName(), AssetType.Prefab);
            AsyncOperationHandle <GameObject>?loader = null;

            if (obj == null)
            {
                loader = AddressableResLoader.InstantiateAsync(info.loadPath);
                yield return(loader);

                if (loader.Value.Result != null)
                {
                    obj = loader.Value.Result;
                    //加载完了放入对象池
                    PoolManager.instance.AddItemToPool(info.loadPath, info.loadPath.GetAssetName(), obj, AssetType.Prefab, true);
                }
            }
            data.isLoading = false;

            if (obj != null)
            {
                obj.transform.SetParent(m_root);
                UIBase ui = obj.GetOrAddComponent <UIBase>();
                if (!ui.IsInit)
                {
                    ui.InitUI(info);
                }
                ui.CloseSelfEvent += OnClickCloseEvent;
                data.uiBase        = ui;
                PushUIDataToAllStack(data);
                PushUIToSelfStack(data);
                if (data.info.maskType != UIMaskType.None)
                {
                    ManagerMask();
                }

                IEnumerator iterator = ui.ShowUI(info.userDatas);
                info.iterator = iterator;
                yield return(iterator);

                showEvent?.TryInvoke(ui);

                LoadUIComplete(data);

                IEnumerator iterator2 = ui.LoadCompleteUI(info.userDatas);
                info.iterator = iterator2;
                yield return(iterator2);

                info.iterator = null;
            }
            else
            {
                Debug.LogError("Load " + data.info.loadPath + " fail!!! ");
            }
        }
Пример #2
0
        public IEnumerator PreLoad()
        {
            for (int i = 0; i < preLoad.Count; i++)
            {
                string path   = $"{loadPath}{preLoad[i]}.prefab";
                var    handle = AddressableResLoader.InstantiateAsync(path);
                yield return(handle);

                if (handle.Result != null)
                {
                    handle.Result.AddComponent <DontDestroyOnload>();
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Mask是特殊的加载,不会放在UIStack里面,也不会放在对象池里面,只有显示和隐藏
        /// </summary>
        /// <param name="sortingOrder"></param>
        /// <param name="isClick"></param>
        private IEnumerator LoadMask()
        {
            var handle = AddressableResLoader.InstantiateAsync(UIPath.MaskUI.loadPath);

            yield return(handle);

            if (handle.Result != null)
            {
                GameObject obj = handle.Result;
                obj.transform.SetParent(m_root);
                m_mask = obj.GetOrAddComponent <MaskManager>();
                m_mask.InitUI(UIPath.MaskUI);
                yield return(m_mask.ShowUI());
            }
            else
            {
                Debug.LogError("load file failur:" + UIPath.MaskUI.loadPath);
            }
        }
Пример #4
0
        private IEnumerator LoadUI(UIConfig config, object[] userData = null)
        {
            var    data      = PrePushToAllStack(config, userData);
            string path      = config.loadPath;
            string assetName = path.GetAssetName();
            /**先从对象池里面取,取不出来才加载**/
            GameObject obj = m_pool.GetFromPool(path, assetName);
            AsyncOperationHandle <GameObject>?loader = null;

            if (!obj)
            {
                loader = AddressableResLoader.InstantiateAsync(path);
                yield return(loader);

                if (loader.Value.Result)
                {
                    obj = loader.Value.Result;
                    /**加载完放入对象池里面**/
                    m_pool.AddItemToPool(path, assetName, obj, true, true);
                }
            }
            if (obj)
            {
                obj.transform.SetParent(root);
                UIBase ui = obj.GetOrAddComponent <UIBase>();
                ui.SetUIData(data.userDatas);
                InitUIBase(ui);
                yield return(ui.ShowUI());

                RemoveLoadUIData(data);
                OpenUIManagerMask(ui);
            }
            else
            {
                Debug.LogError("Load " + config.loadPath + " fail!!! ");
            }
        }
Пример #5
0
        /// <summary>
        /// Mask是特殊的加载,不会放在UIStack里面,也不会放在对象池里面,只有显示和隐藏
        /// 所以游戏开始的时候就要开始加载
        /// </summary>
        /// <param name="sortingOrder"></param>
        /// <param name="isClick"></param>
        public IEnumerator LoadMask()
        {
            UIConfig config;

            if (m_dic.TryGetValue(UIName.MaskUI, out config))
            {
                var handle = AddressableResLoader.InstantiateAsync(config.loadPath);
                yield return(handle);

                if (handle.Result != null)
                {
                    GameObject obj = handle.Result;
                    obj.transform.SetParent(root);
                    m_mask = obj.GetOrAddComponent <MaskManager>();
                    m_mask.InitUI();
                    m_mask.clickCloseMaskEvent += CloseCurUI;
                    m_mask.HideUI();
                }
                else
                {
                    Debug.LogError("load file failur:" + config.loadPath);
                }
            }
        }