/// <summary> /// 使用的前提是rectt的类型为双局中 /// </summary> /// <param name="anchoType"></param> /// <param name="parentRectt"></param> /// <param name="rectt"></param> public static void SetNormalAnchor(AnchoType anchoType, RectTransform parentRectt, RectTransform rectt) { Vector2 sizeDelta = rectt.sizeDelta; Vector2 p_sizeDelta = parentRectt.sizeDelta; Vector2 anchoredPosition = rectt.anchoredPosition; float xmin = 0; float xmax = 0; float ymin = 0; float ymax = 0; float xSize = 0; float ySize = 0; float xanchored = 0; float yanchored = 0; if ((anchoType & AnchoType.Up) == AnchoType.Up) { ymin = ymax = 1; yanchored = anchoredPosition.y - p_sizeDelta.y * 0.5f; ySize = sizeDelta.y; } if ((anchoType & AnchoType.Down) == AnchoType.Down) { ymin = ymax = 0; yanchored = anchoredPosition.y + p_sizeDelta.y * 0.5f; ySize = sizeDelta.y; } if ((anchoType & AnchoType.Left) == AnchoType.Left) { xmin = xmax = 0; xanchored = anchoredPosition.x + p_sizeDelta.x * 0.5f; xSize = sizeDelta.x; } if ((anchoType & AnchoType.Right) == AnchoType.Right) { xmin = xmax = 1; xanchored = anchoredPosition.x - p_sizeDelta.x * 0.5f; xSize = sizeDelta.x; } if ((anchoType & AnchoType.XStretch) == AnchoType.XStretch) { xmin = 0; xmax = 1; xanchored = anchoredPosition.x; xSize = sizeDelta.x - p_sizeDelta.x; } if ((anchoType & AnchoType.YStretch) == AnchoType.YStretch) { ymin = 0; ymax = 1; yanchored = anchoredPosition.y; ySize = sizeDelta.y - p_sizeDelta.y; } if ((anchoType & AnchoType.XCenter) == AnchoType.XCenter) { xmin = xmax = 0.5f; xanchored = anchoredPosition.x; xSize = sizeDelta.x; } if ((anchoType & AnchoType.YCenter) == AnchoType.YCenter) { ymin = ymax = 0.5f; yanchored = anchoredPosition.y; ySize = sizeDelta.y; } rectt.anchorMin = new Vector2(xmin, ymin); rectt.anchorMax = new Vector2(xmax, ymax); rectt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, sizeDelta.x); rectt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, sizeDelta.y); rectt.sizeDelta = new Vector2(xSize, ySize); rectt.anchoredPosition = new Vector2(xanchored, yanchored); }
public UINode(Transform transform, LayerInfo layerInfo = null) { this.layerInfo = layerInfo; this.transform = transform; anchoType = AnchoType.Custom; }