/// <summary> /// 先把加载信息放入全局的堆栈里面 /// </summary> private LoadUIData PrePushToAllStack(UIConfig config, params object[] userDatas) { LoadUIData data = new LoadUIData(); data.uiConfig = config; data.isLoading = true; data.isClosed = false; data.userDatas = userDatas; m_loadDatas.Add(data); return(data); }
/// <summary> /// 是否可以加载UI /// </summary> /// <param name="uiInfo"></param> /// <param name="showEvent"></param> /// <param name="userData"></param> /// <returns></returns> private bool CanStartLoadUI(UIConfig config, object[] userDatas = null) { if (m_loadDatas.Count <= 0) { return(true); } for (int i = 0; i < m_loadDatas.Count; i++) { var data = m_loadDatas[i]; if (data.uiConfig.Equals(config)) { if (data.isLoading) { Debug.Log($"{data.uiConfig.loadPath } is Loading!!!!"); data.userDatas = userDatas; return(false); } } } return(true); }
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!!! "); } }