mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 12:47:38 +02:00
Remix properties panel now scrolls correctly when the curor is over an inputfield (#395)
Co-authored-by: Jenny Crowe <jakobwcrowe@berkeley.edu>
This commit is contained in:
62
Assets/Scripts/LevelEditor/ChiScrollRect.cs
Normal file
62
Assets/Scripts/LevelEditor/ChiScrollRect.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace HeavenStudio.Editor
|
||||
{
|
||||
// Thank you Unity forums!
|
||||
// https://forum.unity.com/threads/scroll-view-does-not-scroll-with-mousewheel-when-mouse-is-over-a-button-inside-the-scroll-view.848848/
|
||||
|
||||
public class ChiScrollRect : ScrollRect, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
private static string mouseScrollWheelAxis = "Mouse ScrollWheel";
|
||||
private bool swallowMouseWheelScrolls = true;
|
||||
private bool isMouseOver = false;
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
isMouseOver = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
isMouseOver = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Detect the mouse wheel and generate a scroll. This fixes the issue where Unity will prevent our ScrollRect
|
||||
// from receiving any mouse wheel messages if the mouse is over a raycast target (such as a button).
|
||||
if (isMouseOver && IsMouseWheelRolling())
|
||||
{
|
||||
var delta = UnityEngine.Input.GetAxis(mouseScrollWheelAxis);
|
||||
|
||||
PointerEventData pointerData = new PointerEventData(EventSystem.current);
|
||||
pointerData.scrollDelta = new Vector2(0f, delta * scrollSensitivity);
|
||||
|
||||
swallowMouseWheelScrolls = false;
|
||||
OnScroll(pointerData);
|
||||
swallowMouseWheelScrolls = true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnScroll(PointerEventData data)
|
||||
{
|
||||
if (IsMouseWheelRolling() && swallowMouseWheelScrolls)
|
||||
{
|
||||
// Eat the scroll so that we don't get a double scroll when the mouse is over an image
|
||||
}
|
||||
else
|
||||
{
|
||||
base.OnScroll(data);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsMouseWheelRolling()
|
||||
{
|
||||
return UnityEngine.Input.GetAxis(mouseScrollWheelAxis) != 0;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user