fix tooltip with scaled window

This commit is contained in:
minenice55 2022-06-28 15:57:32 -04:00
parent ec4f710caa
commit 2a87dd3aff
2 changed files with 17 additions and 11 deletions

View file

@ -25,7 +25,7 @@ namespace HeavenStudio.Editor
{ {
private Initializer Initializer; private Initializer Initializer;
[SerializeField] private Canvas MainCanvas; [SerializeField] public Canvas MainCanvas;
[SerializeField] public Camera EditorCamera; [SerializeField] public Camera EditorCamera;
[SerializeField] public GameObject EditorLetterbox; [SerializeField] public GameObject EditorLetterbox;

View file

@ -27,27 +27,33 @@ namespace HeavenStudio.Editor
private void Update() private void Update()
{ {
Vector2 anchoredPosition = Input.mousePosition; Vector3 anchoredPosition = Input.mousePosition;
Camera camera = Camera.main;
Vector3 canvasScale = Editor.instance.MainCanvas.transform.localScale;
Vector2 scale = new Vector2(canvasScale.x, canvasScale.y);
float toolTipScale = camera.pixelWidth / 1280f;
if (anchoredPosition.x + background.rect.width > canvasRect.rect.width) if (anchoredPosition.x + background.rect.width * toolTipScale > camera.pixelWidth)
{ {
anchoredPosition.x = canvasRect.rect.width - background.rect.width; anchoredPosition.x = camera.pixelWidth - background.rect.width * toolTipScale;
} }
if (anchoredPosition.x < 0) if (anchoredPosition.x < -camera.pixelWidth)
{ {
anchoredPosition.x = 0; anchoredPosition.x = -camera.pixelWidth;
} }
if (anchoredPosition.y + background.rect.height > canvasRect.rect.height) if (anchoredPosition.y + background.rect.height * toolTipScale > camera.pixelHeight)
{ {
anchoredPosition.y = canvasRect.rect.height - background.rect.height; anchoredPosition.y = camera.pixelHeight - background.rect.height * toolTipScale;
} }
if (anchoredPosition.y < 0) if (anchoredPosition.y < -camera.pixelHeight)
{ {
anchoredPosition.y = 0; anchoredPosition.y = -camera.pixelHeight;
} }
rectTransform.anchoredPosition = anchoredPosition; anchoredPosition.z = camera.nearClipPlane;
anchoredPosition = camera.ScreenToWorldPoint(anchoredPosition);
rectTransform.anchoredPosition = anchoredPosition / scale;
} }
public static void OnEnter(string tooltipText, string altTooltipText) public static void OnEnter(string tooltipText, string altTooltipText)