How can I make scalable(contracting) EditorWindow UI(not in-game UI) like in inspector example?
When speaking about the UI, all objects have a
RectTransform instead of a
Transform. One of it's values is the
Anchors one. An anchor basically defines where the child is "attached" in relation to it's parent. Each object has 2 anchors, Min (for bottom-left corner) and Max (for top-right). Their values go from 0 to 1, which signifies the percentage of the screen width/height.
If for example you've set both anchors like this:
anchorMin.x = 0.1; anchorMax.x = 0.9; anchorMin.y = 0.1; anchorMax.y = 0.9;
RectTransform's positions are all 0, then all edges of that object will be 10% away from the edge of the screen, regardless of screen size (The object basically stretches from 10% to 90% of screen size).
Keep in mind that if both
y of both anchors are the same value, the Inspector changes, and gives you a new "width" or "height" field, which you can use to give a specific size to your element. So with this example:
anchorMin.x = 0.1; anchorMax.x = 0.9; anchorMin.y = 0.5; anchorMax.y = 0.5;
This object is now stretching only horizontally from 10% to 90% of screen space, and it's also anchored vertically in the middle of the screen, but on a single point. This means you can give it your own height (for example 100px) and the object will now stretch to fit the screen horizontally, while keeping itself at 100px height.