Fix UIPanels being broken after resolution changes, better checks on size/position

This commit is contained in:
Sinai
2021-05-18 19:55:27 +10:00
parent c134c1752e
commit 5aef8ddc99
11 changed files with 153 additions and 112 deletions

View File

@ -250,15 +250,9 @@ namespace UnityExplorer.UI.Panels
Vector2 diff = (Vector2)mousePos - m_lastDragPosition;
m_lastDragPosition = mousePos;
var pos = Panel.localPosition + (Vector3)diff;
Panel.localPosition = Panel.localPosition + (Vector3)diff;
// Prevent panel going oustide screen bounds
var halfW = Screen.width * 0.5f;
var halfH = Screen.height * 0.5f;
pos.x = Math.Max(-halfW, Math.Min(pos.x, halfW - Panel.rect.width));
pos.y = Math.Max(-halfH + Panel.rect.height, Math.Min(pos.y, halfH));
Panel.localPosition = pos;
UIPanel.EnsureValidPosition(Panel);
}
public void OnEndDrag()
@ -425,6 +419,9 @@ namespace UnityExplorer.UI.Panels
if ((Vector2)mousePos == m_lastResizePos)
return;
if (mousePos.x < 0 || mousePos.y < 0 || mousePos.x > Screen.width || mousePos.y > Screen.height)
return;
m_lastResizePos = mousePos;
float diffX = (float)((decimal)diff.x / Screen.width);