// 添加窗口物件 public void AddView(IUIWndView view, WndLayerDef layer) { RectTransform trans = GetWndLayerTrans(layer); if (view == null || trans == null) { return; } view.GetTransform().SetParent(trans, false); }
/// <summary> /// 计算屏幕坐标系下的准星坐标 /// </summary> public void CalculateFrontSightScreenPos() { //将坐标转换为屏幕坐标 IUIWnd tmpWnd = UISystem.Instance.GetWnd(WndID.WND_ID_WAR_FRONTSIGHT); if (tmpWnd != null) { IUIWndView tmpView = tmpWnd.GetWndView(); if (tmpView != null && tmpView.GetTransform() != null) { Vector2 ScreenPos = RectTransformUtility.WorldToScreenPoint(UISystem.Instance.GetCamera(), tmpView.GetTransform().position); m_FrontSightScreenPos = ScreenPos; } } }
public static void RegisterWndViewForLayer(IUIWndView _uView) { if (_uView.GetTransform() == null || _uView.GetUIWnd() == null) { return; } USpeedUILayerElement viewLayerElement = _uView.GetTransform().GetComponent <USpeedUILayerElement>() ?? _uView.GetTransform().gameObject.AddComponent <USpeedUILayerElement>(); viewLayerElement.UILayerElementType = USpeedUILayerElement.EUILayerElementType.ELET_UI; viewLayerElement.IsUIRequirRaycaster = true; //重新调整canvas的Sorting信息 //viewLayerElement = true; //调整SortingLayer,目前都统一用一个Layer,layer多的话会影响渲染效率 viewLayerElement.SortingLayerName = CalculateLayerName(_uView.GetUIWnd().GetLayer()); //调整SortingOrder viewLayerElement.SortingLayerOrder = CheckSortingOrderRange(CalculateWndViewLayerOrder(_uView)); //计算Layer的Z轴坐标 layerDef越大,越靠近相机 //Vector3 tmpPos = _nLayer.GetTransform.localPosition; //tmpPos.z = ((int)WndLayerDef.WND_LAYER_MAX - (int)_nLayerDef) * LayerZAxisDistance; //_nLayer.GetTransform.localPosition = tmpPos; }
public static int CalculateWndViewLayerOrder(IUIWndView _uView) { return(_uView.GetTransform().GetSiblingIndex() * WndViewLayerOrderDelta + WndViewLayerOrderDelta); }