Compare commits

...

2 Commits

Author SHA1 Message Date
jym
500eb79f2f Merge branch 'main' into jym/250623_02 2025-06-24 11:26:05 +09:00
정영민
99e54f4a23 Winodw UI 크기 확장 오류 수정 2025-06-23 17:01:58 +09:00
3 changed files with 74 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
using System.Drawing.Printing;
using UnityEngine;
using Studio.UI;
using System.Collections.Generic;
namespace Studio.Manage
{
@@ -15,7 +16,9 @@ namespace Studio.Manage
Texture2D cursor_DownLeft;
Texture2D cursor_DownRight;
public List<Texture2D> cursors = new List<Texture2D>();
public UI_GUIWindow currentUseGUIWindow;
public Texture2D currentCursor;
public override void Init()
{
@@ -27,6 +30,15 @@ namespace Studio.Manage
cursor_UpRight = Resources.Load<Texture2D>("Images/cursor_diag_b");
cursor_DownLeft = Resources.Load<Texture2D>("Images/cursor_diag_b");
cursor_DownRight = Resources.Load<Texture2D>("Images/cursor_diag_a");
cursors.Add(cursor_Up);
cursors.Add(cursor_Down);
cursors.Add(cursor_Left);
cursors.Add(cursor_Right);
cursors.Add(cursor_UpLeft);
cursors.Add(cursor_UpRight);
cursors.Add(cursor_DownLeft);
cursors.Add(cursor_DownRight);
}
public void ChangeMouseCursor(ResizeDirection dir)
@@ -65,6 +77,8 @@ namespace Studio.Manage
void ChangeCursor(Texture2D cursorTexture)
{
currentCursor = cursorTexture;
Vector2 hotspot = new Vector2(16, 16);
if (cursorTexture == null)
@@ -74,5 +88,16 @@ namespace Studio.Manage
Cursor.SetCursor(cursorTexture, hotspot, CursorMode.Auto);
}
public bool IsResizeCursor()
{
foreach(var cursor in cursors)
{
if (currentCursor == cursor)
{
return true;
}
}
return false;
}
}
}

View File

@@ -29,6 +29,7 @@ namespace Studio.UI
public class UI_GUIWindow : UIBase, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerMoveHandler, IDragHandler
{
RectTransform rect;
public UI_GUIWindowHeader header;
public RectTransform Area;
CursorManager cursorManager;
@@ -66,7 +67,7 @@ namespace Studio.UI
raycastImg.raycastTarget = true;
raycastImg.color = Color.clear;
var header = GetComponentInChildren<UI_GUIWindowHeader>();
header = GetComponentInChildren<UI_GUIWindowHeader>();
if (header == null)
{
Debug.LogError("GUIWindow에 Header가 없음: " + gameObject.name);
@@ -93,6 +94,8 @@ namespace Studio.UI
if (!isCanResize)
return;
SetHeaderSetting();
switch (state)
{
case GUIState.Resize:
@@ -122,7 +125,7 @@ namespace Studio.UI
public void OnPointerEnter(PointerEventData eventData)
{
cursorManager.currentUseGUIWindow = this;
cursorManager.currentUseGUIWindow = this;
}
public ResizeDirection GetHandleDirection()
@@ -164,7 +167,7 @@ namespace Studio.UI
state = GUIState.Move;
}
void SetResizeState(ResizeDirection dir)
public void SetResizeState(ResizeDirection dir)
{
if (dir == ResizeDirection.None)
{
@@ -290,42 +293,47 @@ namespace Studio.UI
{
if (rect == null) return false;
// 기존 사이즈와 비교
Vector2 currentSize = rect.rect.size;
bool isShrinking = newSize.x <= currentSize.x && newSize.y <= currentSize.y;
// 축소면 무조건 허용
if (isShrinking)
return true;
// 확장이라면 화면 안에 있을 때만 허용
return IsRectTransformInsideCanvas(rect);
return WouldBeInsideCanvas(rect, newSize);
}
public bool IsRectTransformInsideCanvas(RectTransform targetRect)
public bool WouldBeInsideCanvas(RectTransform targetRect, Vector2 newSize)
{
if (targetRect == null)
return false;
Canvas rootCanvas = targetRect.GetComponentInParent<Canvas>();
if (rootCanvas == null || !rootCanvas.pixelRect.Contains(Vector2.zero))
if (rootCanvas == null)
return false;
RectTransform canvasRect = rootCanvas.GetComponent<RectTransform>();
// 임시로 코너 계산용 RectTransform 만들기
Vector3[] worldCorners = new Vector3[4];
targetRect.GetWorldCorners(worldCorners);
foreach (var corner in worldCorners)
// 현재 pivot 기준으로 위치를 보정한 코너 계산
Vector3 position = targetRect.position;
Vector2 pivot = targetRect.pivot;
Vector2 scaledSize = new Vector2(newSize.x * targetRect.lossyScale.x, newSize.y * targetRect.lossyScale.y);
Vector3 bottomLeft = position - new Vector3(pivot.x * scaledSize.x, pivot.y * scaledSize.y);
Vector3 topRight = bottomLeft + new Vector3(scaledSize.x, scaledSize.y);
Vector3[] testCorners = new Vector3[] { bottomLeft, new Vector3(topRight.x, bottomLeft.y), new Vector3(bottomLeft.x, topRight.y), topRight };
foreach (var corner in testCorners)
{
Vector3 viewportPoint = RectTransformUtility.WorldToScreenPoint(null, corner);
Vector3 screenPoint = RectTransformUtility.WorldToScreenPoint(null, corner);
// Canvas 크기 기준으로 판단
if (viewportPoint.x < 0 || viewportPoint.y < 0 ||
viewportPoint.x > Screen.width || viewportPoint.y > Screen.height)
if (screenPoint.x < 0 || screenPoint.x > Screen.width ||
screenPoint.y < 0 || screenPoint.y > Screen.height)
{
return false; // 하나라도 화면 밖에 있음
return false;
}
}
@@ -354,5 +362,21 @@ namespace Studio.UI
{
transform.SetAsLastSibling();
}
private void SetHeaderSetting()
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(header.rectTransform, Input.mousePosition, null, out var localPoint);
if (header.rectTransform.rect.Contains(localPoint))
{
if (cursorManager.IsResizeCursor())
{
header.enabled = false;
}
else
{
header.enabled = true;
}
}
}
}
}

View File

@@ -1,3 +1,5 @@
using Studio.Manage;
using UnityEngine.UI;
using UnityEngine;
using UnityEngine.EventSystems;
using XRLib.UI;
@@ -6,17 +8,23 @@ namespace Studio.UI
{
public class UI_GUIWindowHeader : UIBase, IPointerDownHandler
{
CursorManager cursorManager;
UI_GUIWindow parentGUIWindow;
public override void AfterAwake()
{
cursorManager = ManagerHub.instance.Get<CursorManager>();
parentGUIWindow = GetParentGUIWindow();
}
public void OnPointerDown(PointerEventData eventData)
{
if (cursorManager.IsResizeCursor())
return;
parentGUIWindow.SetPanelAsLastSibling();
parentGUIWindow.SetMoveState();
}
UI_GUIWindow GetParentGUIWindow()