using MyFrameworkPure;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace MyFrameworkPure
{
///
/// 在VR交互中,用射线点击滚动框里的按钮时,由于手部的轻微抖动,可能会触发滚动框滚动,导致按钮点击无效;将此脚本添加到按钮上可以避免此问题
///
public class DragEventBlocker : MonoBehaviour
, IDragHandler
{
public void OnDrag(PointerEventData eventData)
{
}
public static void Block(GameObject go)
{
Selectable[] selectables = go.GetComponentsInChildren(true);
selectables.ForEach(x =>
{
DragEventBlocker dragEventBlocker = x.gameObject.GetOrAddCompoent();
dragEventBlocker.enabled = true;
});
}
public static void RemoveBlock(GameObject go)
{
Selectable[] selectables = go.GetComponentsInChildren(true);
selectables.ForEach(x =>
{
DragEventBlocker dragEventBlocker = x.gameObject.GetOrAddCompoent();
dragEventBlocker.enabled = false;
});
}
public static void BlockAllScrollRect()
{
ScrollRect[] scrollRects = GameObjectTool.FindObjectsOfType();
scrollRects?.ForEach(x =>
{
Selectable[] selectables = x.GetComponentsInChildren(true);
selectables.ForEach(y => y.gameObject.GetOrAddCompoent());
});
}
public static void RemoveAllBlock()
{
DragEventBlocker[] dragEventBlockers = GameObjectTool.FindObjectsOfType();
dragEventBlockers?.DestroyImmediate(true);
}
}
}