So, i think about relative anchor position by the uisprite. Its need for make window works correct, change their dimensions and now it's not need to reposition all sprites on it.
And i add UITable new directions. Now its able to view as RightDown, RightUp, LeftDown, LeftUp (and Down/Up if you already use them as RightDown/RightUp):
UITable.cs - find RepositionVariableSize void function (you need to change the second FOR):
for (int i = 0, imax = children.Count; i < imax; ++i)
{
Transform t = children[i];
Bounds b = bounds[y, x];
Bounds br = boundsRows[x];
Bounds bc = boundsCols[y];
Vector3 pos = t.localPosition;
float yset;
if (direction == Direction.Down || direction == Direction.RightDown || direction == Direction.LeftDown)
{
pos.x = xOffset + b.extents.x - b.center.x;
pos.y = -yOffset - b.extents.y - b.center.y;
yset = (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y;
if (direction == Direction.LeftDown) {
pos.y -= yset;
pos.x = -xOffset - b.extents.x - b.center.x;
pos.x -= b.min.x - br.min.x + padding.x;
} else {
pos.y += yset;
pos.x += b.min.x - br.min.x + padding.x;
}
}
else if (direction == Direction.Up || direction == Direction.RightUp || direction == Direction.LeftUp)
{
pos.x = xOffset + b.extents.x - b.center.x;
pos.y = yOffset + b.extents.y - b.center.y;
yset = (b.max.y - b.min.y - bc.max.y + bc.min.y) * 0.5f - padding.y;
if (direction == Direction.LeftUp) {
pos.y -= yset;
pos.x = -xOffset - b.extents.x - b.center.x;
pos.x -= b.min.x - br.min.x + padding.x;
} else {
pos.y += yset;
pos.x += b.min.x - br.min.x + padding.x;
}
}
xOffset += br.max.x - br.min.x + padding.x * 2f;
t.localPosition = pos;
if (++x >= columns && columns > 0)
{
x = 0;
++y;
xOffset = 0f;
yOffset += bc.size.y + padding.y * 2f;
}
}
And add some new directions:
public enum Direction
{
Down,
Up,
RightDown,
RightUp,
LeftDown,
LeftUp,
}
----------------------
Now, lets change UIAnchor.cs (you need to replace Update function)
void Update ()
{
if (uiCamera != null || uiSprite != null)
{
Vector3 v;
Vector3 vScale;
Rect rect;
if (uiSprite != null) {
vScale = uiSprite.cachedTransform.localScale;
v = uiCamera.WorldToScreenPoint(uiSprite.cachedTransform.position);
rect.x = v.x - vScale.x / 2.0f;
rect.y = v.y - vScale.y / 2.0f;
rect.width = vScale.x;
rect.height = vScale.y;
} else {
rect = uiCamera.pixelRect;
}
float cx = (rect.xMin + rect.xMax) * 0.5f;
float cy = (rect.yMin + rect.yMax) * 0.5f;
v
= new Vector3
(cx, cy, depthOffset
);
if (side != Side.Center)
{
if (side == Side.Right || side == Side.TopRight || side == Side.BottomRight)
{
v.x = rect.xMax;
}
else if (side == Side.Top || side == Side.Center || side == Side.Bottom)
{
v.x = cx;
}
else
{
v.x = rect.xMin;
}
if (side == Side.Top || side == Side.TopRight || side == Side.TopLeft)
{
v.y = rect.yMax;
}
else if (side == Side.Left || side == Side.Center || side == Side.Right)
{
v.y = cy;
}
else
{
v.y = rect.yMin;
}
}
float screenWidth = rect.width;
float screenHeight = rect.height;
v.x += relativeOffset.x * screenWidth;
v.y += relativeOffset.y * screenHeight;
if (uiCamera != null && uiCamera.orthographic)
{
v.x = Mathf.RoundToInt(v.x);
v.y = Mathf.RoundToInt(v.y);
if (halfPixelOffset && mIsWindows)
{
v.x -= 0.5f;
v.y += 0.5f;
}
}
// Convert from screen to world coordinates, since the two may not match (UIRoot set to manual size)
if (uiCamera != null) v = uiCamera.ScreenToWorldPoint(v);
// Wrapped in an 'if' so the scene doesn't get marked as 'edited' every frame
if (mTrans.position != v) mTrans.position = v;
}
}
And of course add some variable:
public UISprite uiSprite = null;
Now you can add some background as UISprite to anchor element and all elements in that anchor will set their positions according on it.
Hope, it helps for somebody