public void SetInsetAndSizeFromParentEdge(RectTransform.Edge edge, float inset, float size) { int axis = (edge != RectTransform.Edge.Top && edge != RectTransform.Edge.Bottom) ? 0 : 1; bool topOrRightAligned = edge == RectTransform.Edge.Top || edge == RectTransform.Edge.Right; float value = !topOrRightAligned ? 0 : 1; Vector2 temp = default(Vector2); // Used to bypass property assignment // anchorMin temp = this.anchorMin; temp[axis] = value; this.anchorMin = temp; // anchorMax temp = this.anchorMax; temp[axis] = value; this.anchorMax = temp; // sizeDelta temp = this.sizeDelta; temp[axis] = size; this.sizeDelta = temp; // anchoredPosition temp = this.anchoredPosition; temp[axis] = ((!topOrRightAligned) ? (inset + size * this.pivot[axis]) : (-inset - size * (1f - this.pivot[axis]))); this.anchoredPosition = temp; // position // NOTE: Might be able to defer this until second axis temp = this.position; temp[axis] = Misc.AnchoredPositionToWorldPosition((RectTransform)parent, anchoredPosition, pivot, anchorMin, anchorMax)[axis]; this.position = temp; // localPosition // NOTE: Might be able to defer this until second axis temp = this.localPosition; temp[axis] = parent.InverseTransformPoint(this.position)[axis]; this.localPosition = temp; }