screen adjust
This commit is contained in:
@@ -1120,29 +1120,52 @@ public class UIWidget : UIRect
|
||||
Vector3 pos = trans.localPosition;
|
||||
Vector2 pvt = pivotOffset;
|
||||
|
||||
float sizeAdjust = UIRoot.GetPixelSizeAdjustment(gameObject);
|
||||
#region add by chenbin
|
||||
Vector4 offsetRect = NGUITools.offsetRect;
|
||||
float leftOffset = offsetRect.x;
|
||||
float rightOffset = offsetRect.z;
|
||||
float topOffset = offsetRect.y;
|
||||
UIPanel panel = null;
|
||||
#endregion
|
||||
|
||||
|
||||
// Attempt to fast-path if all anchors match
|
||||
if (leftAnchor.target == bottomAnchor.target &&
|
||||
leftAnchor.target == rightAnchor.target &&
|
||||
leftAnchor.target == topAnchor.target)
|
||||
{
|
||||
Vector3[] sides = leftAnchor.GetSides(parent);
|
||||
//add by chenbin
|
||||
panel = leftAnchor.target.GetComponent<UIPanel>();
|
||||
if (panel != null)
|
||||
{
|
||||
leftOffset *= panel.width;
|
||||
rightOffset *= panel.width;
|
||||
topOffset *= panel.height;
|
||||
} else
|
||||
{
|
||||
leftOffset = 0;
|
||||
rightOffset = 0;
|
||||
topOffset = 0;
|
||||
}
|
||||
Vector3[] sides = leftAnchor.GetSides(parent);
|
||||
|
||||
if (sides != null)
|
||||
{
|
||||
lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute;
|
||||
rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute;
|
||||
bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute;
|
||||
tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute;
|
||||
lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute + leftOffset;
|
||||
rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute - rightOffset;
|
||||
bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute - topOffset;
|
||||
tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute - topOffset;
|
||||
mIsInFront = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Anchored to a single transform
|
||||
Vector3 lp = GetLocalPos(leftAnchor, parent);
|
||||
lt = lp.x + leftAnchor.absolute;
|
||||
bt = lp.y + bottomAnchor.absolute;
|
||||
rt = lp.x + rightAnchor.absolute;
|
||||
tt = lp.y + topAnchor.absolute;
|
||||
lt = lp.x + leftAnchor.absolute + leftOffset;
|
||||
bt = lp.y + bottomAnchor.absolute - topOffset;
|
||||
rt = lp.x + rightAnchor.absolute - rightOffset;
|
||||
tt = lp.y + topAnchor.absolute - topOffset;
|
||||
mIsInFront = (!hideIfOffScreen || lp.z >= 0f);
|
||||
}
|
||||
}
|
||||
@@ -1153,15 +1176,29 @@ public class UIWidget : UIRect
|
||||
// Left anchor point
|
||||
if (leftAnchor.target)
|
||||
{
|
||||
//add by chenbin
|
||||
panel = leftAnchor.target.GetComponent<UIPanel>();
|
||||
if (panel != null)
|
||||
{
|
||||
leftOffset *= panel.width;
|
||||
rightOffset *= panel.width;
|
||||
topOffset *= panel.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftOffset = 0;
|
||||
rightOffset = 0;
|
||||
topOffset = 0;
|
||||
}
|
||||
Vector3[] sides = leftAnchor.GetSides(parent);
|
||||
|
||||
if (sides != null)
|
||||
{
|
||||
lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute;
|
||||
lt = NGUIMath.Lerp(sides[0].x, sides[2].x, leftAnchor.relative) + leftAnchor.absolute + leftOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
lt = GetLocalPos(leftAnchor, parent).x + leftAnchor.absolute;
|
||||
lt = GetLocalPos(leftAnchor, parent).x + leftAnchor.absolute + leftOffset;
|
||||
}
|
||||
}
|
||||
else lt = pos.x - pvt.x * mWidth;
|
||||
@@ -1169,15 +1206,29 @@ public class UIWidget : UIRect
|
||||
// Right anchor point
|
||||
if (rightAnchor.target)
|
||||
{
|
||||
//add by chenbin
|
||||
panel = rightAnchor.target.GetComponent<UIPanel>();
|
||||
if (panel != null)
|
||||
{
|
||||
leftOffset *= panel.width;
|
||||
rightOffset *= panel.width;
|
||||
topOffset *= panel.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftOffset = 0;
|
||||
rightOffset = 0;
|
||||
topOffset = 0;
|
||||
}
|
||||
Vector3[] sides = rightAnchor.GetSides(parent);
|
||||
|
||||
if (sides != null)
|
||||
{
|
||||
rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute;
|
||||
rt = NGUIMath.Lerp(sides[0].x, sides[2].x, rightAnchor.relative) + rightAnchor.absolute - rightOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
rt = GetLocalPos(rightAnchor, parent).x + rightAnchor.absolute;
|
||||
rt = GetLocalPos(rightAnchor, parent).x + rightAnchor.absolute - rightOffset;
|
||||
}
|
||||
}
|
||||
else rt = pos.x - pvt.x * mWidth + mWidth;
|
||||
@@ -1185,15 +1236,29 @@ public class UIWidget : UIRect
|
||||
// Bottom anchor point
|
||||
if (bottomAnchor.target)
|
||||
{
|
||||
//add by chenbin
|
||||
panel = bottomAnchor.target.GetComponent<UIPanel>();
|
||||
if (panel != null)
|
||||
{
|
||||
leftOffset *= panel.width;
|
||||
rightOffset *= panel.width;
|
||||
topOffset *= panel.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftOffset = 0;
|
||||
rightOffset = 0;
|
||||
topOffset = 0;
|
||||
}
|
||||
Vector3[] sides = bottomAnchor.GetSides(parent);
|
||||
|
||||
if (sides != null)
|
||||
{
|
||||
bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute;
|
||||
bt = NGUIMath.Lerp(sides[3].y, sides[1].y, bottomAnchor.relative) + bottomAnchor.absolute - topOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
bt = GetLocalPos(bottomAnchor, parent).y + bottomAnchor.absolute;
|
||||
bt = GetLocalPos(bottomAnchor, parent).y + bottomAnchor.absolute - topOffset;
|
||||
}
|
||||
}
|
||||
else bt = pos.y - pvt.y * mHeight;
|
||||
@@ -1201,26 +1266,41 @@ public class UIWidget : UIRect
|
||||
// Top anchor point
|
||||
if (topAnchor.target)
|
||||
{
|
||||
//add by chenbin
|
||||
panel = topAnchor.target.GetComponent<UIPanel>();
|
||||
if (panel != null)
|
||||
{
|
||||
leftOffset *= panel.width;
|
||||
rightOffset *= panel.width;
|
||||
topOffset *= panel.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
leftOffset = 0;
|
||||
rightOffset = 0;
|
||||
topOffset = 0;
|
||||
}
|
||||
Vector3[] sides = topAnchor.GetSides(parent);
|
||||
|
||||
if (sides != null)
|
||||
{
|
||||
tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute;
|
||||
tt = NGUIMath.Lerp(sides[3].y, sides[1].y, topAnchor.relative) + topAnchor.absolute - topOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
tt = GetLocalPos(topAnchor, parent).y + topAnchor.absolute;
|
||||
tt = GetLocalPos(topAnchor, parent).y + topAnchor.absolute - topOffset;
|
||||
}
|
||||
}
|
||||
else tt = pos.y - pvt.y * mHeight + mHeight;
|
||||
}
|
||||
|
||||
|
||||
// Calculate the new position, width and height
|
||||
Vector3 newPos = new Vector3(Mathf.Lerp(lt, rt, pvt.x), Mathf.Lerp(bt, tt, pvt.y), pos.z);
|
||||
newPos.x = Mathf.Round(newPos.x);
|
||||
newPos.y = Mathf.Round(newPos.y);
|
||||
|
||||
int w = Mathf.FloorToInt(rt - lt + 0.5f);
|
||||
int w = Mathf.FloorToInt(rt - lt + 0.5f);
|
||||
int h = Mathf.FloorToInt(tt - bt + 0.5f);
|
||||
|
||||
// Maintain the aspect ratio if requested and possible
|
||||
|
||||
Reference in New Issue
Block a user