screen adjust
This commit is contained in:
@@ -1727,19 +1727,22 @@ static public class NGUITools
|
||||
mGameSize = (Vector2)s_GetSizeOfMainGameView.Invoke (null, null);
|
||||
}
|
||||
return mGameSize;
|
||||
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#else
|
||||
/// <summary>
|
||||
/// Size of the game view cannot be retrieved from Screen.width and Screen.height when the game view is hidden.
|
||||
/// </summary>
|
||||
|
||||
|
||||
static public Vector2 screenSize { get { return new Vector2(Screen.width, Screen.height); } }
|
||||
//static public Vector2 screenSize { get { return new Vector2(Screen.safeArea.width, Screen.safeArea.height); } }
|
||||
#endif
|
||||
|
||||
#region add by chenbin
|
||||
#region add by chenbin
|
||||
|
||||
public static void updateAll (Transform tr)
|
||||
public static void updateAll (Transform tr)
|
||||
{
|
||||
UILabel label = tr.GetComponent<UILabel> ();
|
||||
if (label != null) {
|
||||
@@ -1813,22 +1816,49 @@ static public class NGUITools
|
||||
}
|
||||
}
|
||||
|
||||
public static Rect wrapRect4IphoneX(Rect rect) {
|
||||
return wrapRect4Fringe (rect);
|
||||
}
|
||||
public static Vector4 _offsetRect;
|
||||
public static Vector4 offsetRect
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_offsetRect == null)
|
||||
{
|
||||
float left = Screen.safeArea.x;
|
||||
float right = Screen.width - Screen.safeArea.width - left;
|
||||
float top = Screen.safeArea.y;
|
||||
float bottom = Screen.height - Screen.safeArea.height - top;
|
||||
|
||||
public static Rect wrapRect4Fringe(Rect rect) {
|
||||
if (isFringe) {
|
||||
if (rect.width > rect.height) {
|
||||
float offsetWidth = rect.width * (1 - rateFringe);
|
||||
return new Rect ((int)(offsetWidth / 2), 0, rect.width - offsetWidth, rect.height);
|
||||
} else {
|
||||
float offsetHight = rect.height * (1 - rateFringe);
|
||||
return new Rect (0, (int)(offsetHight / 2), rect.width, rect.height - offsetHight);
|
||||
_offsetRect = new Vector4(left/Screen.width, top / Screen.height, right / Screen.width, bottom / Screen.height);
|
||||
}
|
||||
} else {
|
||||
return rect;
|
||||
return _offsetRect;
|
||||
}
|
||||
set{
|
||||
_offsetRect = value;
|
||||
}
|
||||
}
|
||||
|
||||
public static Rect wrapRect4Fringe(GameObject go, Rect rect) {
|
||||
//if (isFringe) {
|
||||
// if (rect.width > rect.height) {
|
||||
// float offsetWidth = rect.width * (1 - rateFringe);
|
||||
// return new Rect ((int)(offsetWidth / 2), 0, rect.width - offsetWidth, rect.height);
|
||||
// } else {
|
||||
// float offsetHight = rect.height * (1 - rateFringe);
|
||||
// return new Rect (0, (int)(offsetHight / 2), rect.width, rect.height - offsetHight);
|
||||
// }
|
||||
//} else {
|
||||
// return rect;
|
||||
//}
|
||||
Vector4 offset = offsetRect;
|
||||
float left = rect.width * offset.x;
|
||||
float right = rect.width * offset.z;
|
||||
float top = rect.height * offset.y;
|
||||
float bottom = rect.height * offset.w;
|
||||
rect.x += left;
|
||||
rect.width -= (left + right);
|
||||
rect.y += bottom;
|
||||
rect.height -= (top + bottom);
|
||||
return rect;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -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