/// <summary> /// 重新计算显示的长宽 /// </summary> protected void CaleSizeDelta(UPopupMenuUpdateParam _nParam) { float sumHeight; float sumItemComponentHeight = m_ItemComponent.GetRange(0, m_ItemComponent.Count).SumFloat(GetItemHeight); float sumSeparationLineComponentHeight = m_LineGroupIDDic.Select(x => x.Value).ToList().GetRange(0, m_LineGroupIDDic.Count).SumFloat(GetItemHeight); sumHeight = sumItemComponentHeight + sumSeparationLineComponentHeight + (ListLayout.Spacing.y * (m_ItemComponent.Count + m_LineGroupIDDic.Count)); Vector2 sizeDelta = Container.sizeDelta; sizeDelta.y = sumHeight + 4; Container.sizeDelta = sizeDelta; }
/// <summary> /// 重新计算显示的位置 /// </summary> protected void CalePosition(UPopupMenuUpdateParam _nParam) { Vector3[] Corners = new Vector3[4]; Vector3 newPos = Vector3.zero; Vector2 newPivot = Vector2.zero; UIWidgets.UTooltipExtensionMethods.GetWorldCorners(_nParam.PopupTarget.gameObject, _nParam.RootCanvas, _nParam.UICamera, ref Corners); UIWidgets.UTooltipExtensionMethods.SetPosition(_nParam.PopupTipPostion, Corners, Container, _nParam.RootCanvas, _nParam.UICamera, ref newPos); //只有子列表不使用模态 if (!_nParam.IsModalUsed) {//次级列表以上级列表组件边框的右上角为锚点计算偏移值 newPivot = Container.pivot; newPivot.y = 1; Container.pivot = newPivot; } Container.SetPosition(newPos); //如果在窗口边缘则重新计算显示位置 if (_nParam.PopupOverflowCheck) { UTooltipOverflow overflow; UIWidgets.UTooltipExtensionMethods.GetOverflow(Container, _nParam.RootCanvas, _nParam.UICamera, out overflow); if (overflow.IsAny) { UIWidgets.UTooltipExtensionMethods.SetPosition(overflow.SuggestNewPosition(_nParam.PopupTipPostion), Corners, Container , _nParam.RootCanvas, _nParam.UICamera, ref newPos); //只有子列表不使用模态 if (!_nParam.IsModalUsed) { newPivot = Container.pivot; newPivot.y = 1; Container.pivot = newPivot; } Container.SetPosition(newPos); } } //重置一下Z轴,有可能是取边框角顶点时改点Z轴有 newPos = Container.localPosition; newPos.x += 0.5f; newPos.y -= 0.5f; newPos.z = 0; Container.localPosition = newPos; }
/// <summary> /// 添加模态管理 /// </summary> /// <param name="_nParam"></param> protected void AddModalHelper(UPopupMenuUpdateParam _nParam) { if (_nParam.PopupModalColor == null) { _nParam.PopupModalColor = new Color(0f, 0f, 0f, 0f); } if (_nParam.PopupView == null) { Trace.LogWarning("这里没有赋值Popup所在的View,所以不会进行模态处理。"); return; } m_ModalKey = UIWidgets.ModalHelper.Open(this, _nParam.PopupModalSprite, _nParam.PopupModalColor, _nParam.ModalClickAction, Container); Container.SetParent(_nParam.RootCanvas.transform, false); Container.SetAsLastSibling(); }
/// <summary> /// 更新弹出框显示数据 /// </summary> /// <param name="_nParam"></param> public void UpdatePopup(UPopupMenuUpdateParam _nParam) { RemoveLastSeparationLine(); CaleSizeDelta(_nParam); CalePosition(_nParam); if (_nParam.IsModalUsed) { AddModalHelper(_nParam); } else { Container.SetParent(_nParam.RootCanvas.transform, false); Container.SetAsLastSibling(); } m_LastView = _nParam.PopupView; Container.gameObject.SetActive(true); }