커서 아이콘이 초기화 되지 않는 버그 수정 #3
@@ -53,6 +53,8 @@ namespace XED.UI
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
Texture2D cursor_DownRight;
|
Texture2D cursor_DownRight;
|
||||||
|
|
||||||
|
Vector2 mousePos;
|
||||||
|
|
||||||
Direction direction;
|
Direction direction;
|
||||||
|
|
||||||
Vector2 initialMousePos;
|
Vector2 initialMousePos;
|
||||||
@@ -78,31 +80,34 @@ namespace XED.UI
|
|||||||
|
|
||||||
private void OnEnable()
|
private void OnEnable()
|
||||||
{
|
{
|
||||||
state = GUIState.None;
|
InitializeState();
|
||||||
transform.SetAsLastSibling();
|
transform.SetAsLastSibling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
InitializeState();
|
||||||
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
bool mouseDown = Input.GetMouseButtonDown(0);
|
bool mouseDown = Input.GetMouseButtonDown(0);
|
||||||
bool mouseUp = Input.GetMouseButtonUp(0);
|
bool mouseUp = Input.GetMouseButtonUp(0);
|
||||||
Vector2 mousePos = Input.mousePosition;
|
mousePos = Input.mousePosition;
|
||||||
|
|
||||||
if (mouseUp)
|
if (mouseUp)
|
||||||
{
|
{
|
||||||
state = GUIState.None;
|
InitializeState();
|
||||||
SetPanelPivot(initialPivot);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChangeMouseCursor(mousePos);
|
ChangeMouseCursor();
|
||||||
|
|
||||||
Direction handleDirection = GetHandleDirection(mousePos);
|
Direction handleDirection = GetHandleDirection();
|
||||||
if (mouseDown && handleDirection != Direction.None)
|
if (mouseDown && handleDirection != Direction.None)
|
||||||
{
|
{
|
||||||
SetResizeState(handleDirection);
|
SetResizeState(handleDirection);
|
||||||
}
|
}
|
||||||
|
else if (mouseDown && IsRectContainsMouse(header))
|
||||||
if (mouseDown && IsHeaderRange(mousePos))
|
|
||||||
{
|
{
|
||||||
SetMoveState();
|
SetMoveState();
|
||||||
}
|
}
|
||||||
@@ -118,18 +123,18 @@ namespace XED.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsHeaderRange(Vector2 pos)
|
bool IsRectContainsMouse(RectTransform range)
|
||||||
{
|
{
|
||||||
Vector2 localPoint;
|
Vector2 localPoint;
|
||||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(header, pos, null, out localPoint);
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(range, mousePos, null, out localPoint);
|
||||||
|
|
||||||
return header.rect.Contains(localPoint);
|
return header.rect.Contains(localPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
Direction GetHandleDirection(Vector2 pos)
|
Direction GetHandleDirection()
|
||||||
{
|
{
|
||||||
Vector2 localPoint;
|
Vector2 localPoint;
|
||||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, pos, null, out localPoint);
|
RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, mousePos, null, out localPoint);
|
||||||
|
|
||||||
if (!rect.rect.Contains(localPoint)) return Direction.None;
|
if (!rect.rect.Contains(localPoint)) return Direction.None;
|
||||||
|
|
||||||
@@ -279,12 +284,12 @@ namespace XED.UI
|
|||||||
rect.localPosition -= deltaPosition;
|
rect.localPosition -= deltaPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeMouseCursor(Vector2 pos)
|
public void ChangeMouseCursor()
|
||||||
{
|
{
|
||||||
if (state == GUIState.Resize)
|
if (state == GUIState.Resize)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (GetHandleDirection(pos))
|
switch (GetHandleDirection())
|
||||||
{
|
{
|
||||||
case Direction.Up:
|
case Direction.Up:
|
||||||
ChangeCursor(cursor_Up);
|
ChangeCursor(cursor_Up);
|
||||||
@@ -327,5 +332,12 @@ namespace XED.UI
|
|||||||
|
|
||||||
Cursor.SetCursor(cursorTexture, hotspot, CursorMode.Auto);
|
Cursor.SetCursor(cursorTexture, hotspot, CursorMode.Auto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InitializeState()
|
||||||
|
{
|
||||||
|
state = GUIState.None;
|
||||||
|
SetPanelPivot(initialPivot);
|
||||||
|
ChangeCursor(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user