本文整理汇总了C#中UnityEngine.Rect.clampToScreen方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.clampToScreen方法的具体用法?C# Rect.clampToScreen怎么用?C# Rect.clampToScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Rect
的用法示例。
在下文中一共展示了Rect.clampToScreen方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: drawToolTip
internal void drawToolTip()
{
if (!destroyed) {
if (showTooltip && (command.ToolTip != null) && (command.ToolTip.Trim().Length > 0)) {
Vector2 mousePos = Utils.getMousePosition();
Vector2 size = TooltipStyle.CalcSize(new GUIContent(command.ToolTip));
Rect rect = new Rect(mousePos.x, mousePos.y + 20, size.x, size.y);
float origY = rect.y;
rect = rect.clampToScreen();
// clamping moved the tooltip up -> reposition above mouse cursor
if (rect.y < origY) {
rect.y = mousePos.y - size.y - 5;
rect = rect.clampToScreen();
}
int oldDepth = GUI.depth;
GUI.depth = -1000;
GUILayout.BeginArea(rect);
GUILayout.Label(command.ToolTip, TooltipStyle);
GUILayout.EndArea();
GUI.depth = oldDepth;
}
}
}
示例2: autoPositionAgainstParent
private AutoPositionResult autoPositionAgainstParent(Vector2 size, Rect parentRect, bool parentIsSingleColumn, RelativePosition preferredPosition)
{
Vector2 posLeft = new Vector2(parentRect.x - size.x - BUTTON_SPACING, parentRect.y + (parentRect.height - size.y) / 2);
Vector2 posRight = new Vector2(parentRect.x + parentRect.width + BUTTON_SPACING, posLeft.y);
Vector2 posAbove = new Vector2(parentRect.x + (parentRect.width - size.x) / 2, parentRect.y - size.y - BUTTON_SPACING);
Vector2 posBelow = new Vector2(posAbove.x, parentRect.y + parentRect.height + BUTTON_SPACING);
// figure out potential positions based on blocking important GUI
bool canUseLeft = !isBlockingImportantGUI(posLeft, size);
bool canUseRight = !isBlockingImportantGUI(posRight, size);
bool canUseAbove = !isBlockingImportantGUI(posAbove, size);
bool canUseBelow = !isBlockingImportantGUI(posBelow, size);
// all blocked, let's ignore blocking things
if (!canUseLeft && !canUseRight && !canUseAbove && !canUseBelow) {
canUseLeft = true;
canUseRight = true;
canUseAbove = true;
canUseBelow = true;
}
// figure out potential positions based on being off-screen
canUseLeft = canUseLeft && !isOffScreenX(posLeft, size);
canUseRight = canUseRight && !isOffScreenX(posRight, size);
canUseAbove = canUseAbove && !isOffScreenY(posAbove, size);
canUseBelow = canUseBelow && !isOffScreenY(posBelow, size);
// all off-screen, let's position it anywhere
if (!canUseLeft && !canUseRight && !canUseAbove && !canUseBelow) {
canUseLeft = true;
canUseRight = true;
canUseAbove = true;
canUseBelow = true;
}
// switch preferred position to the opposite side if blocked
if ((preferredPosition == RelativePosition.LEFT) && !canUseLeft && canUseRight) {
preferredPosition = RelativePosition.RIGHT;
} else if ((preferredPosition == RelativePosition.RIGHT) && !canUseRight && canUseLeft) {
preferredPosition = RelativePosition.LEFT;
} else if ((preferredPosition == RelativePosition.ABOVE) && !canUseAbove && canUseBelow) {
preferredPosition = RelativePosition.BELOW;
} else if ((preferredPosition == RelativePosition.BELOW) && !canUseBelow && canUseAbove) {
preferredPosition = RelativePosition.ABOVE;
}
RelativePosition finalPosition;
if (((preferredPosition == RelativePosition.ABOVE) && canUseAbove) ||
((preferredPosition == RelativePosition.BELOW) && canUseBelow) ||
((preferredPosition == RelativePosition.LEFT) && canUseLeft) ||
((preferredPosition == RelativePosition.RIGHT) && canUseRight)) {
// preferred position is good to go
finalPosition = preferredPosition;
} else if (parentIsSingleColumn) {
// default positioning for single column: right > left > above > below
if (canUseRight) {
finalPosition = RelativePosition.RIGHT;
} else if (canUseLeft) {
finalPosition = RelativePosition.LEFT;
} else if (canUseAbove) {
finalPosition = RelativePosition.ABOVE;
} else {
finalPosition = RelativePosition.BELOW;
}
} else {
// default positioning: above > below > right > left
if (canUseAbove) {
finalPosition = RelativePosition.ABOVE;
} else if (canUseBelow) {
finalPosition = RelativePosition.BELOW;
} else if (canUseRight) {
finalPosition = RelativePosition.RIGHT;
} else {
finalPosition = RelativePosition.LEFT;
}
}
Vector2 pos;
switch (finalPosition) {
case RelativePosition.ABOVE:
pos = posAbove;
break;
case RelativePosition.BELOW:
pos = posBelow;
break;
case RelativePosition.LEFT:
pos = posLeft;
break;
case RelativePosition.RIGHT:
pos = posRight;
break;
default:
throw new Exception("unknown final position: " + finalPosition);
}
Rect r = new Rect(pos.x, pos.y, size.x, size.y);
r = r.clampToScreen();
pos = new Vector2(r.x, r.y);
//.........这里部分代码省略.........
示例3: autoPositionAgainstParent
private Vector2 autoPositionAgainstParent(Vector2 size, Rect parentRect, bool parentIsSingleColumn)
{
Vector2 posRight = new Vector2(parentRect.x + parentRect.width + BUTTON_SPACING, parentRect.y + (parentRect.height - size.y) / 2);
Vector2 posLeft = new Vector2(parentRect.x - size.x - BUTTON_SPACING, posRight.y);
Vector2 posAbove = new Vector2(parentRect.x + (parentRect.width - size.x) / 2, parentRect.y - size.y - BUTTON_SPACING);
Vector2 posBelow = new Vector2(posAbove.x, parentRect.y + parentRect.height + BUTTON_SPACING);
bool canUseRight = !isOffScreenOrBlockingImportantGUI(posRight, size);
bool canUseLeft = !isOffScreenOrBlockingImportantGUI(posLeft, size);
bool canUseAbove = !isOffScreenOrBlockingImportantGUI(posAbove, size);
bool canUseBelow = !isOffScreenOrBlockingImportantGUI(posBelow, size);
Vector2 pos;
if (!canUseRight && !canUseLeft && !canUseAbove && !canUseBelow) {
// all blocked, use default
pos = parentIsSingleColumn ? posRight : posAbove;
} else if (parentIsSingleColumn) {
// right > left > above > below
if (canUseRight) {
pos = posRight;
} else if (canUseLeft) {
pos = posLeft;
} else if (canUseAbove) {
pos = posAbove;
} else {
pos = posBelow;
}
} else {
// above > below > right > left
if (canUseAbove) {
pos = posAbove;
} else if (canUseBelow) {
pos = posBelow;
} else if (canUseRight) {
pos = posRight;
} else {
pos = posLeft;
}
}
Rect r = new Rect(pos.x, pos.y, size.x, size.y);
r = r.clampToScreen();
return new Vector2(r.x, r.y);
}
示例4: isOffScreenY
private bool isOffScreenY(Vector2 pos, Vector2 size)
{
Rect r = new Rect(pos.x, pos.y, size.x, size.y);
r = r.clampToScreen();
return r.y != pos.y;
}
示例5: isOffScreenOrBlockingImportantGUI
private bool isOffScreenOrBlockingImportantGUI(Vector2 pos, Vector2 size)
{
Rect r = new Rect(pos.x, pos.y, size.x, size.y);
if (!r.intersectsImportantGUI()) {
r = r.clampToScreen();
return (r.x != pos.x) || (r.y != pos.y);
} else {
return true;
}
}