Note that there’s actually a bunch of different values that can be shown in the inspector of a RectTransform depending on how the transform’s anchors are set. In your example hierarchy, I think the anchors are going to be dictated by some of the layout classes, so there is presumably one specific answer for this exact example, but in the more general case getting “the values in the inspector” is actually a bunch of different problems with different answers depending on the anchors. For modifying stuff through script, it’s probably better to focus on what’s conveniently available in script instead of trying to convert everything to and from the inspector values.
I’m moderately sure that RectTransform.rect.size should give you useful size data, though. The position of that rectangle isn’t directly useful for much because it’s in the transform’s own coordinate space (and therefore doesn’t necessarily change even when the object moves).
You could alternately try using RectTransform.sizeDelta, but since that’s the size relative to the anchors it won’t be the same as the actual total size unless all 4 anchors are set to the same point.
To set the size to a specific value, you can use SetSizeWithCurrentAnchors. (Or you can set sizeDelta directly, but again, remember that might not be the “true” size.)
RectTransform.anchoredPosition is the recommended way to modify a RectTransform’s position relative to the parent, and works great if you want to offset the current position by some amount, but figuring out what its absolute value means is…complex.
To get the size and position of one RectTransform relative to another, there’s a couple techniques you could try.
Perhaps the simplest option is to use Transform.TransformPoint to convert points from a given transform’s local space into world space, and then InverseTransformPoint to transform those into the local space of some other transform. (I haven’t personally tried this.)
Another option is to multiply RectTransform.anchorMin/anchorMax by the parent’s size to determine the anchors’ positions in the parent’s coordinate space, then use RectTransform.offsetMin/offsetMax to get the transform’s coordinates relative to those anchors. Here’s a snippet of some code I recently wrote some code that works on this principle:
Vector2 parentSize = parentRT.rect.size;
// Calculate our corners relative to parent
Vector2 ourMinCorner = ourRT.anchorMin.ComponentMultiply(parentSize) + ourRT.offsetMin;
Vector2 ourMaxCorner = ourRT.anchorMax.ComponentMultiply(parentSize) + ourRT.offsetMax;
…where “ComponentMultiply” is just my personal shortcut for multiplying each of the coordinates independently:
public static Vector2 ComponentMultiply(this Vector2 v, Vector2 other)
{
return new Vector2(v.x * other.x, v.y * other.y);
}
You might also need to multiply/divide by transform.localScale somewhere in there if the objects in your hierarchy aren’t all at scale 1.