// The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to
        // get data for ray pointers and canvas mouse pointers.

        /// <summary>
        /// State for a pointer controlled by a world space ray. E.g. gaze pointer
        /// </summary>
        /// <returns></returns>
        virtual protected MouseState GetGazePointerData()
        {
            // Get the OVRRayPointerEventData reference
            GCSeriesPointerEventData leftData;

            GetPointerData(kMouseLeftId, out leftData, true);
            leftData.Reset();
            //Now set the world space ray. This ray is what the user uses to point at UI elements
            leftData.worldSpaceRay = new Ray(FCore.penPosition, FCore.penDirection);
            //leftData.scrollDelta = GetExtraScrollDelta();

            //Populate some default values
            leftData.button           = PointerEventData.InputButton.Left;
            leftData.useDragThreshold = true;
            // Perform raycast to find intersections with world
            eventSystem.RaycastAll(leftData, m_RaycastResultCache);
            var raycast = FindFirstRaycast(m_RaycastResultCache);

            leftData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();
            //hitPos = new Vector3(1000f, 1000f, 1000f);
            GCSeriesRaycaster ovrRaycaster = raycast.module as GCSeriesRaycaster;

            // We're only interested in intersections from OVRRaycasters
            if (ovrRaycaster)
            {
                // The Unity UI system expects event data to have a screen position
                // so even though this raycast came from a world space ray we must get a screen
                // space position for the camera attached to this raycaster for compatability
                leftData.position = ovrRaycaster.GetScreenPosition(raycast);


                // Find the world position and normal the Graphic the ray intersected
                RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>();
                if (graphicRect != null)
                {
                    // Set are gaze indicator with this world position and normal
                    Vector3 worldPos = raycast.worldPosition; //射到UI上的点
                                                              //Vector3 normal = GetRectTransformNormal(graphicRect);
                                                              //hitPos = worldPos;
                }

                //获取父物体是否有button组件
                Button uiButton = raycast.gameObject.GetComponentInParent <Button>();
                if (uiButton)
                {
                    Transform[] transforms = raycast.gameObject.GetComponentsInParent <Transform>();
                    //在限定的层级里寻找是否存在button组件,存在且不与上次的物体同名,则说明需要响应shake操作
                    int traverseTime = transforms.Length < traverseButtonTime ? transforms.Length : traverseButtonTime;
                    for (int i = 0; i < traverseTime; i++)
                    {
                        if (transforms[i].name == uiButton.name)
                        {
                            if (lastCheckObj)
                            {
                                if (lastCheckObj.name != uiButton.name)
                                {
                                    FCore.PenShake();
                                    lastCheckObj = uiButton.gameObject;
                                }
                            }
                            else
                            {
                                FCore.PenShake();
                                lastCheckObj = uiButton.gameObject;
                            }
                        }
                    }
                }
                else
                {
                    Toggle toggle = raycast.gameObject.GetComponentInParent <Toggle>();
                    if (toggle)
                    {
                        Transform[] transforms = raycast.gameObject.GetComponentsInParent <Transform>();
                        //在限定的层级里寻找是否存在button组件,存在且不与上次的物体同名,则说明需要响应shake操作
                        int traverseTime = transforms.Length < traverseToggleTime ? transforms.Length : traverseToggleTime;
                        for (int i = 0; i < traverseTime; i++)
                        {
                            if (transforms[i].name == toggle.name)
                            {
                                if (lastCheckObj)
                                {
                                    if (lastCheckObj.name != toggle.name)
                                    {
                                        FCore.PenShake();
                                        lastCheckObj = toggle.gameObject;
                                    }
                                }
                                else
                                {
                                    FCore.PenShake();
                                    lastCheckObj = toggle.gameObject;
                                }
                            }
                        }
                    }
                    else
                    {
                        lastCheckObj = null;
                    }
                }
            }
            else
            {
                //没有点到UI 或者说是移出UI
                lastCheckObj = null;
            }
            m_PenState.SetButtonState(PointerEventData.InputButton.Left, GetPenButtonState(), leftData);
            return(m_PenState);
        }
예제 #2
0
        /*-------------支持投屏和触屏修改部分--------------*/

        // The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to
        // get data for ray pointers and canvas mouse pointers.

        /// <summary>
        /// State for a pointer controlled by a world space ray. E.g. gaze pointer
        /// </summary>
        /// <returns></returns>
        virtual protected MouseState GetGazePointerData()
        {
            // Get the OVRRayPointerEventData reference
            GCSeriesPointerEventData leftData;

            GetPointerData(kMouseLeftId, out leftData, true);
            leftData.Reset();

            leftData.position = GCInput.mouseUIPosition;

            //Now set the world space ray. This ray is what the user uses to point at UI elements
            leftData.worldSpaceRay = new Ray(FCore.penPosition, FCore.penDirection);
            //leftData.scrollDelta = GetExtraScrollDelta();

            //Populate some default values
            leftData.button           = PointerEventData.InputButton.Left;
            leftData.useDragThreshold = true;
            // Perform raycast to find intersections with world
            m_RaycastResultCache.Clear();
            eventSystem.RaycastAll(leftData, m_RaycastResultCache);
            var raycast = FindFirstRaycast(m_RaycastResultCache);

            leftData.pointerCurrentRaycast = raycast;

            //hitPos = new Vector3(1000f, 1000f, 1000f);

            GCSeriesRaycaster ovrRaycaster = raycast.module as GCSeriesRaycaster;

            if (!curPenRay)
            {
                curPenRay = GameObject.FindObjectOfType <PenRay>();
            }

            bool isClickButtonOrToggle = false;

            // We're only interested in intersections from OVRRaycasters
            if (ovrRaycaster)
            {
                // The Unity UI system expects event data to have a screen position
                // so even though this raycast came from a world space ray we must get a screen
                // space position for the camera attached to this raycaster for compatability

                leftData.position = ovrRaycaster.GetScreenPosition(raycast);

                // Find the world position and normal the Graphic the ray intersected
                RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>();
                if (graphicRect != null)
                {
                    // Set are gaze indicator with this world position and normal
                    Vector3 worldPos = raycast.worldPosition; //射到UI上的点
                                                              //Vector3 normal = GetRectTransformNormal(graphicRect);
                                                              //hitPos = worldPos;

                    if (curPenRay)
                    {
                        curPenRay.hitUI_bool    = true;
                        curPenRay.hitUIWorldPos = worldPos;
                    }
                }


                //获取父物体是否有button组件
                Button uiButton = raycast.gameObject.GetComponentInParent <Button>();
                if (uiButton)
                {
                    Transform[] transforms = raycast.gameObject.GetComponentsInParent <Transform>();
                    //在限定的层级里寻找是否存在button组件,存在且不与上次的物体同名,则说明需要响应shake操作
                    int traverseTime = transforms.Length < traverseButtonTime ? transforms.Length : traverseButtonTime;
                    for (int i = 0; i < traverseTime; i++)
                    {
                        if (transforms[i].name == uiButton.name)
                        {
                            isClickButtonOrToggle = true;
                            if (lastCheckObj)
                            {
                                if (lastCheckObj.name != uiButton.name)
                                {
                                    FCore.PenShake();
                                    lastCheckObj = uiButton.gameObject;
                                }
                            }
                            else
                            {
                                FCore.PenShake();
                                lastCheckObj = uiButton.gameObject;
                            }
                        }
                    }
                }
                else
                {
                    Toggle toggle = raycast.gameObject.GetComponentInParent <Toggle>();
                    if (toggle)
                    {
                        Transform[] transforms = raycast.gameObject.GetComponentsInParent <Transform>();
                        //在限定的层级里寻找是否存在button组件,存在且不与上次的物体同名,则说明需要响应shake操作
                        int traverseTime = transforms.Length < traverseToggleTime ? transforms.Length : traverseToggleTime;
                        for (int i = 0; i < traverseTime; i++)
                        {
                            if (transforms[i].name == toggle.name)
                            {
                                isClickButtonOrToggle = true;
                                if (lastCheckObj)
                                {
                                    if (lastCheckObj.name != toggle.name)
                                    {
                                        FCore.PenShake();
                                        lastCheckObj = toggle.gameObject;
                                    }
                                }
                                else
                                {
                                    FCore.PenShake();
                                    lastCheckObj = toggle.gameObject;
                                }
                            }
                        }
                    }
                    else
                    {
                        lastCheckObj = null;
                    }
                }
            }
            else
            {
                if (curPenRay)
                {
                    curPenRay.hitUI_bool = false;
                    //没有点到UI 或者说是移出UI
                    lastCheckObj = null;
                }
            }

            if (curPenRay)
            {
                curPenRay.hitGameObject = raycast.gameObject;
            }
            if (!isClickButtonOrToggle)
            {
                m_PenState.SetButtonState(PointerEventData.InputButton.Left, GetPenButtonState(), leftData);
            }
            else
            {
                m_PenState.SetButtonState(PointerEventData.InputButton.Left, GetPenButtonClickToggleOrButton(), leftData);
            }


            //F3D.AppLog.AddMsg($"GCSeriesInputModule.eventSystem.RaycastAll.Count = {m_RaycastResultCache.Count}");
            //m_PenState.SetButtonState(PointerEventData.InputButton.Left, PointerEventData.FramePressState.Released, leftData);

            //情况1:默认笔命中结果 (命中有交互功能UI)

            //情况2:笔没有命中 鼠标也没有命中 释放按压状态
            if (raycast.gameObject == null)
            {
                m_PenState.SetButtonState(PointerEventData.InputButton.Left, GCInput.GetStateForMouseButton(0), leftData);
            }
            //情况3:笔没有命中  鼠标命中了
            else if (raycast.gameObject != null && !(raycast.module is GCSeriesRaycaster))
            {
                curPenRay.hitGameObject   = null;
                leftData.useDragThreshold = false;
                leftData.delta            = Vector2.zero;
                m_PenState.SetButtonState(PointerEventData.InputButton.Left, GCInput.GetStateForMouseButton(0), leftData);
            }
            //情况4:如果触笔命中了(但是无交互功能的UI) 则使用鼠标命中结果
            else if (raycast.gameObject == null || (raycast.module is GCSeriesRaycaster && raycast.gameObject.GetComponent <Interactable>() == null))
            {
                foreach (var item in m_RaycastResultCache)
                {
                    if (item.module is GCSeriesRaycaster)
                    {
                        continue;
                    }
                    if (item.gameObject == null)
                    {
                        continue;
                    }
                    // F3D.AppLog.AddMsg($"GetGazePointerData {item.gameObject.name}");
                    //第一个鼠标输入数据命中的对象处理
                    curPenRay.hitGameObject        = null;
                    leftData.position              = GCInput.mouseUIPosition;
                    leftData.pointerCurrentRaycast = item;
                    leftData.useDragThreshold      = false;
                    leftData.delta = Vector2.zero;
                    m_PenState.SetButtonState(PointerEventData.InputButton.Left, GCInput.GetStateForMouseButton(0), leftData);

                    break;
                }
            }
            m_RaycastResultCache.Clear();
            //IsPointerOverGameObject判断需要
            leftData.pointerEnter = leftData.pointerCurrentRaycast.gameObject;
            return(m_PenState);
        }