NGUI中 鼠标划出屏幕后,停止对 UIDragScrollView 的 press

using UnityEngine;

/// <summary>
/// NGUI中 鼠标划出屏幕后,停止对 UIDragScrollView 的 press
/// </summary>
public class CheckIsDragOverUI : MonoBehaviour
{
    UIDragScrollView dragSV = null;

    void Start()
    {
        if (null == dragSV)
            dragSV = gameObject.GetComponent<UIDragScrollView>();
    }

    bool isPressing = false;
    void Update()
    {
        if (RuntimePlatform.WindowsEditor == Application.platform || RuntimePlatform.WindowsPlayer == Application.platform)
        {
            if (isPressing)
            {
                if (null != dragSV && null != dragSV.scrollView)
                {
                    //判断鼠标是否划出了屏幕
                    Vector3 mousePostion = Input.mousePosition;
                    GameObject hoverobject = UICamera.Raycast(mousePostion) ? UICamera.lastHit.collider.gameObject : null;
                    if (null == hoverobject)
                    {
                        isPressing = false;
                        dragSV.scrollView.Press(false);
                    }
                }
            }
        }
    }

    void OnPress(bool pressed)
    {
        isPressing = pressed;
    }
}
原文地址:https://www.cnblogs.com/luguoshuai/p/9722940.html