Example #1
0
    private void UpdateU3dPosition()
    {
        if (m_curFrameOriginType == OriginType.U3D_2D_MOUSE || m_curFrameOriginType == OriginType.U3D_2D_TOUCH)
        {
            return; //使用原生输入数据Input.mousePosition  默认相机m_u3dCamera
        }
        API.SPoint point = m_curFrameOriginType == OriginType.U3D_3D_TOUCH ? m_curFrameTouchPosition : m_curFrameMouseScreenPosition;

        //窗口左右
        //转到左下->右上坐标系
        int clientX = point.x - m_u3dWindowRect.left;
        int clientY = m_u3dWindowRect.bottom - point.y;

        //重新映射视屏范围
        int  w2   = m_u3dWindowRect.Width / 2;
        bool left = clientX <= w2;

        clientX = clientX > w2 ? clientX - w2 : clientX;

        float rx = clientX * 1.0f / w2;
        float ry = clientY * 1.0f / m_u3dWindowRect.Height;

        //更新针对UI检测相机使用的坐标
        m_mouseUIPosition = new Vector3(m_mouseUICamera.scaledPixelWidth * rx, m_mouseUICamera.scaledPixelHeight * ry);

        //更新空间用相机和坐标
        m_mouseCamera = left ? m_u3dLeftCamera : m_u3dRightCamera;
        API.Point offset = CameraViewOffest(m_mouseCamera);
        m_mousePosition = new Vector3(m_mouseCamera.scaledPixelWidth * rx + offset.x, m_mouseCamera.scaledPixelHeight * ry + offset.y);
    }
Example #2
0
 private API.SRect GetWindownRect(IntPtr hWnd)
 {
     try
     {
         if (hWnd == IntPtr.Zero)
         {
             return(new API.SRect());
         }
         API.SPoint clientPoint = new API.SPoint();
         if (!API.ClientToScreen(hWnd, ref clientPoint))
         {
             Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.GetWindownRect", $"error{Marshal.GetLastWin32Error()} hWnd:{hWnd}");
             return(new API.SRect());
         }
         API.SRect lpRect = new API.SRect();
         if (!API.GetClientRect(hWnd, out lpRect))
         {
             Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.GetWindownRect", $"error{Marshal.GetLastWin32Error()} hWnd:{hWnd}");
             return(new API.SRect());
         }
         return(new API.SRect(clientPoint.x, clientPoint.y, lpRect.right + clientPoint.x, lpRect.bottom + clientPoint.y));
     }
     catch (Exception ex)
     {
         Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.GetWindownRect", ex);
         return(new API.SRect());
     }
 }
Example #3
0
    private void UpdateProjectorPosition()
    {
        API.SPoint point = m_curFrameMouseScreenPosition;
        if (m_curFrameOriginType == OriginType.PRO_2D_TOUCH || m_curFrameOriginType == OriginType.PRO_3D_TOUCH)
        {
            point = m_curFrameTouchPosition;
        }

        if (m_curFrameOriginType == OriginType.PRO_2D_TOUCH || m_curFrameOriginType == OriginType.PRO_2D_MOUSE)
        {
            //投屏窗口正常不分左右

            //转到左下->右上坐标系
            int   clientX = point.x - m_projectorWindowRect.left;
            int   clientY = m_projectorWindowRect.bottom - point.y;
            float rx      = clientX * 1.0f / m_projectorWindowRect.Width;
            float ry      = clientY * 1.0f / m_projectorWindowRect.Height;

            //更新针对UI检测相机使用的坐标
            m_mouseUIPosition = new Vector3(m_mouseUICamera.scaledPixelWidth * rx, m_mouseUICamera.scaledPixelHeight * ry);

            //更新空间用相机和坐标
            m_mouseCamera = m_projectorLeftCamera;
            API.Point offset = CameraViewOffest(m_mouseCamera);
            m_mousePosition = new Vector3(m_mouseCamera.scaledPixelWidth * rx + offset.x, m_mouseCamera.scaledPixelHeight * ry + offset.y);
        }
        else
        {
            //投屏窗口左右

            //转到左下->右上坐标系
            int clientX = point.x - m_projectorWindowRect.left;
            int clientY = m_projectorWindowRect.bottom - point.y;

            //重新映射视屏范围
            int  w2   = m_projectorWindowRect.Width / 2;
            bool left = clientX <= w2;
            clientX = clientX > w2 ? clientX - w2 : clientX;

            float rx = clientX * 1.0f / w2;
            float ry = clientY * 1.0f / m_projectorWindowRect.Height;

            //更新针对UI检测相机使用的坐标
            m_mouseUIPosition = new Vector3(m_mouseUICamera.scaledPixelWidth * rx, m_mouseUICamera.scaledPixelHeight * ry);

            //更新空间用相机和坐标
            m_mouseCamera = left ? m_projectorLeftCamera : m_projectorRightCamera;
            API.Point offset = CameraViewOffest(m_mouseCamera);
            m_mousePosition = new Vector3(m_mouseCamera.scaledPixelWidth * rx + offset.x, m_mouseCamera.scaledPixelHeight * ry + offset.y);
        }
    }
Example #4
0
    /// <summary>
    /// 处理消息 输出到帧数据
    /// 调用顺序 : 窗口消息=>UI脚本调用输入值=>本脚本Update
    /// 为了同步状态数据和坐标数据帧
    /// </summary>
    private void UpdateMsg()
    {
        m_curFrameInputData.Reset();
        //目前没有去接收处理鼠标移动消息
        if (m_msgList.Count == 0)
        {
            //没有消息:

            //3D主屏鼠标没有消息 => 没有按压状态改变 => 可能坐标改变 => 继续使用m_curFrameMouseScreenPosition
            //3D主屏触屏没有消息 => 没有任何变动

            //投屏鼠标没有消息 => 没有按压状态改变 => 可能坐标改变 => 继续使用m_curFrameMouseScreenPosition
            //投屏触屏没有消息 => 没有任何变动

            //2D主屏鼠标/触屏 => 更新原生Input状态 => 因为后面使用的也是原生Input.mousePosition
            if (m_curFrameOriginType == OriginType.U3D_2D_MOUSE || m_curFrameOriginType == OriginType.U3D_2D_TOUCH)
            {
                m_curFrameInputData.Get(0).Down = Input.GetMouseButtonDown(0);
                m_curFrameInputData.Get(1).Down = Input.GetMouseButtonDown(1);
                m_curFrameInputData.Get(2).Down = Input.GetMouseButtonDown(2);
                m_curFrameInputData.Get(0).Up   = Input.GetMouseButtonUp(0);
                m_curFrameInputData.Get(1).Up   = Input.GetMouseButtonUp(1);
                m_curFrameInputData.Get(2).Up   = Input.GetMouseButtonUp(2);
            }
            return;
        }
        //可能最后使用的触屏位置
        API.SPoint finalPoint = m_msgList[m_msgList.Count - 1].m_point;
        //过滤
        OriginType finalType = m_msgList[m_msgList.Count - 1].m_type;

        for (int i = m_msgList.Count - 1; i >= 0; i--)
        {
            MsgData msg = m_msgList[i];
            if (msg.m_type != finalType)
            {
                m_msgList.RemoveAt(i);
            }
        }
        MouseInputData finalInput = null;

        //合并按压数据
        foreach (MsgData msg in m_msgList)
        {
            if (finalInput == null)
            {
                finalInput = msg.m_data;
            }
            else
            {
                finalInput.Combine(msg.m_data);
            }
        }
        m_msgList.Clear();
        //这样干 至少编辑器里能兼容情况下原生输入
        if (finalType == OriginType.U3D_2D_MOUSE || finalType == OriginType.U3D_2D_TOUCH)
        {
            finalInput.Get(0).Down = Input.GetMouseButtonDown(0);
            finalInput.Get(1).Down = Input.GetMouseButtonDown(1);
            finalInput.Get(2).Down = Input.GetMouseButtonDown(2);
            finalInput.Get(0).Up   = Input.GetMouseButtonUp(0);
            finalInput.Get(1).Up   = Input.GetMouseButtonUp(1);
            finalInput.Get(2).Up   = Input.GetMouseButtonUp(2);
        }

        //数据源切换补充逻辑
        if (m_curFrameOriginType != finalType)
        {
            bool pressed0 = m_recordDownInputData.IsPressedAndNoReleased(0);
            bool pressed1 = m_recordDownInputData.IsPressedAndNoReleased(1);
            bool pressed2 = m_recordDownInputData.IsPressedAndNoReleased(2);
            //补充一次释放
            if (pressed0)
            {
                finalInput.Get(0).Up = true;
            }
            if (pressed1)
            {
                finalInput.Get(1).Up = true;
            }
            if (pressed2)
            {
                finalInput.Get(2).Up = true;
            }
        }

        //当前帧输出状态只要有释放状态 重新记录
        if (finalInput.Get(0).Down)
        {
            m_recordDownInputData.Get(0).Down = true;
        }
        if (finalInput.Get(1).Down)
        {
            m_recordDownInputData.Get(1).Down = true;
        }
        if (finalInput.Get(2).Down)
        {
            m_recordDownInputData.Get(2).Down = true;
        }
        if (finalInput.Get(0).Up)
        {
            m_recordDownInputData.Get(0).Reset();
        }
        if (finalInput.Get(1).Up)
        {
            m_recordDownInputData.Get(1).Reset();
        }
        if (finalInput.Get(2).Up)
        {
            m_recordDownInputData.Get(2).Reset();
        }

        //同步更新数据
        m_curFrameInputData.CopyFrom(finalInput);
        m_curFrameOriginType    = finalType;
        m_curFrameTouchPosition = finalPoint;


        if (m_LogLevel <= Common.LogLevel.DEBUG)
        {
            Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.UpdateMsg", $"curFrameOriginType={m_curFrameOriginType}");
            Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "GCInput.UpdateMsg", $"LeftDown={m_curFrameInputData.GetMouseButtonDown(0)} LeftUp={m_curFrameInputData.GetMouseButtonUp(0)}");
        }
    }
Example #5
0
 public MsgData(OriginType type, MouseInputData data, API.SPoint point)
 {
     m_type  = type;
     m_data  = data;
     m_point = point;
 }