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;
    }
}

 

posted @ 2018-09-29 11:47  小·糊涂仙  阅读(247)  评论(0编辑  收藏  举报