Merge pull request '스크립트 변경 테스트' (#4) from ssl/250428 into ssl/250429
All checks were successful
Code Review / code-review (pull_request) Successful in 22s

Reviewed-on: http://220.90.135.190:3000/neitt/Simulation/pulls/4
This commit was merged in pull request #4.
This commit is contained in:
neitt
2025-04-29 11:46:03 +09:00
2 changed files with 770 additions and 209 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,43 +1,48 @@
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;
public class ManualScroller : MonoBehaviour, IScrollHandler, IBeginDragHandler, IDragHandler, IPointerEnterHandler, IPointerExitHandler
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ManualScroller : MonoBehaviour, IScrollHandler, IPointerEnterHandler, IPointerExitHandler
{
public RectTransform viewport;
public RectTransform content;
public Slider slider;
public float scrollSpeed = 50.0f;
private bool isMouseOver = false;
private Vector2 lastDragPosition;
//private Vector2 lastDragPosition;
void Start()
{
slider.onValueChanged.AddListener(OnSliderValueChanged);
}
public void OnScroll(PointerEventData eventData)
{
if (!isMouseOver) return;
Vector2 pos = content.anchoredPosition;
float max = content.rect.height - viewport.rect.height;
pos.y -= eventData.scrollDelta.y * scrollSpeed;
if (pos.y < 0) pos.y = 0;
if (viewport.rect.height + pos.y > content.rect.height) pos.y = content.rect.height - viewport.rect.height;
if (pos.y > max) pos.y = max;
content.anchoredPosition = pos;
}
public void OnBeginDrag(PointerEventData eventData)
{
if (!isMouseOver) return;
lastDragPosition = eventData.position;
}
public void OnDrag(PointerEventData eventData)
{
if (!isMouseOver) return;
Vector2 delta = eventData.position - lastDragPosition;
Vector2 pos = content.anchoredPosition;
pos.y += delta.y;
content.anchoredPosition = pos;
lastDragPosition = eventData.position;
}
public void OnEndDrag(PointerEventData eventData)
{
slider.value = pos.y / max;
}
//public void OnBeginDrag(PointerEventData eventData)
//{
// if (!isMouseOver) return;
//
// lastDragPosition = eventData.position;
//}
//public void OnDrag(PointerEventData eventData)
//{
// if (!isMouseOver) return;
//
// Vector2 delta = eventData.position - lastDragPosition;
// Vector2 pos = content.anchoredPosition;
// pos.y += delta.y;
// content.anchoredPosition = pos;
// lastDragPosition = eventData.position;
//}
public void OnPointerEnter(PointerEventData eventData)
{
isMouseOver = true;
@@ -47,4 +52,11 @@ public class ManualScroller : MonoBehaviour, IScrollHandler, IBeginDragHandler,
{
isMouseOver = false;
}
public void OnSliderValueChanged(float v)
{
Vector2 pos = content.anchoredPosition;
float max = content.rect.height - viewport.rect.height;
pos.y = max * v;
content.anchoredPosition = pos;
}
}