35 lines
922 B
C#
35 lines
922 B
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class UI_ButtonCursorChanger : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
[Header("바꿀 커서 텍스처")]
|
|
public Texture2D cursorTexture;
|
|
|
|
[Header("커서 핫스팟 (중심 위치)")]
|
|
public Vector2 hotspot = Vector2.zero;
|
|
|
|
private bool isCursorChanged = false;
|
|
|
|
// 마우스가 버튼 위로 올라갔을 때
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (cursorTexture != null && !isCursorChanged)
|
|
{
|
|
Cursor.SetCursor(cursorTexture, hotspot/2, CursorMode.Auto);
|
|
isCursorChanged = true;
|
|
}
|
|
}
|
|
|
|
// 마우스가 버튼을 벗어났을 때
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (isCursorChanged)
|
|
{
|
|
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
|
isCursorChanged = false;
|
|
}
|
|
}
|
|
}
|