Simple Tooltip 에셋 무료인데 쓸만해서 사용하는 친구들 있을거임





https://assetstore.unity.com/packages/tools/gui/simple-tooltip-155804?srsltid=AfmBOoppMUcTpjld_UZDbQ0ryt9w3J9dW5654PEEAPYELzz7Yonjkwf-#reviews

Simple Tooltip | GUI Tools | Unity Asset Store

Use the Simple Tooltip from Norb on your next project. Find this GUI tool & more on the Unity Asset Store.

assetstore.unity.com





원래 Simple Tooltip 은 기본적으로 오른쪽 위로 툴팁이 표기되는데


아래 짤처럼 마우스가 오른쪽이나 위로 너무 가까워지면 툴팁이 잘리는 현상이 발생함.


그걸 보완하기 위해서 스크린안으로 다시 집어 넣는 코드를 추가함. 



18b3d932fced2bfe54b4d2b81af9702dd8b362f95df0daca2d00c0628a0e4c92



아래가 수정된 기능



18b3d932fced0aa378efe4be0fc5703380fafc0866d7eb6f5733a76d939db73d



STController.cs 의 UpdateShow()를 아래와 같이 변경하면됨.

private void UpdateShow()
{
if (showInFrames == -1) return;
if (showInFrames == 0) showNow = true;
if (!showNow) { showInFrames--; return; }

Vector2 mousePos = Input.mousePosition;
Vector2 tooltipSize = rect.rect.size;

float pivotX = 0f;
float pivotY = 0f;

bool IsInsideScreen(Vector2 pos, Vector2 pivot)
{
Vector2 corner = pos - Vector2.Scale(tooltipSize, pivot);
return corner.x >= 0 && corner.x + tooltipSize.x <= Screen.width
&& corner.y >= 0 && corner.y + tooltipSize.y <= Screen.height;
}

Vector2 basePivot = new Vector2(0f, 0f);
if (!IsInsideScreen(mousePos, basePivot))
{
if (mousePos.x + tooltipSize.x > Screen.width)
pivotX = 1f;

if (mousePos.y + tooltipSize.y > Screen.height)
pivotY = 1f;

if (!IsInsideScreen(mousePos, new Vector2(pivotX, pivotY)))
{
pivotX = 0f;
pivotY = 0f;
}
}

rect.pivot = new Vector2(pivotX, pivotY);
rect.anchoredPosition = mousePos;
showInFrames--;
}