Merge pull request '스크립트 변경 테스트' (#4) from ssl/250428 into ssl/250429
All checks were successful
Code Review / code-review (pull_request) Successful in 22s
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:
File diff suppressed because it is too large
Load Diff
@@ -1,43 +1,48 @@
|
|||||||
using Unity.VisualScripting;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
public class ManualScroller : MonoBehaviour, IScrollHandler, IBeginDragHandler, IDragHandler, IPointerEnterHandler, IPointerExitHandler
|
using UnityEngine.UI;
|
||||||
|
public class ManualScroller : MonoBehaviour, IScrollHandler, IPointerEnterHandler, IPointerExitHandler
|
||||||
{
|
{
|
||||||
public RectTransform viewport;
|
public RectTransform viewport;
|
||||||
public RectTransform content;
|
public RectTransform content;
|
||||||
|
public Slider slider;
|
||||||
public float scrollSpeed = 50.0f;
|
public float scrollSpeed = 50.0f;
|
||||||
|
|
||||||
private bool isMouseOver = false;
|
private bool isMouseOver = false;
|
||||||
private Vector2 lastDragPosition;
|
//private Vector2 lastDragPosition;
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
slider.onValueChanged.AddListener(OnSliderValueChanged);
|
||||||
|
}
|
||||||
public void OnScroll(PointerEventData eventData)
|
public void OnScroll(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
if (!isMouseOver) return;
|
if (!isMouseOver) return;
|
||||||
|
|
||||||
Vector2 pos = content.anchoredPosition;
|
Vector2 pos = content.anchoredPosition;
|
||||||
|
float max = content.rect.height - viewport.rect.height;
|
||||||
pos.y -= eventData.scrollDelta.y * scrollSpeed;
|
pos.y -= eventData.scrollDelta.y * scrollSpeed;
|
||||||
if (pos.y < 0) pos.y = 0;
|
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;
|
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)
|
public void OnPointerEnter(PointerEventData eventData)
|
||||||
{
|
{
|
||||||
isMouseOver = true;
|
isMouseOver = true;
|
||||||
@@ -47,4 +52,11 @@ public class ManualScroller : MonoBehaviour, IScrollHandler, IBeginDragHandler,
|
|||||||
{
|
{
|
||||||
isMouseOver = false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user